SCO Unix 3.2 brk()/sbrk() problems????

Yermo M. Lamers yml at grebyn.com
Thu Jan 3 03:36:12 AEST 1991


According to the Programmers Reference Manual, if sbrk() is given a
negative number it should DECREASE the amount of memory allocated for 
the calling process. 

Should this decrease in allocated memory show up in the SZ column of the
ps command?

Under SCO Unix 3.2 when I use sbrk() with a positive argument, the size
of the process as reported by ps -l does get larger, but when I use
sbrk() with a negative argument the process size as reported by ps -l
does not get smaller. It seems to remain constant. (This same problem
also occurs with malloc() and free(). )

I printed out the return value of sbrk() after each call. The value it
returned became smaller after each call in proportion to the magnitude
of the argument to sbrk(). (-32000 in my case).

I used the following code fragment :

int count;
long address;

sleep( 30 );          /* run ps on another screen, SZ around 104 */

for ( count = 0; count < 100; count++ )
   if ( sbrk( 32000 ) == -1 )
      perror( "sbrk error" );

sleep(30);            /* run ps on another screen, SZ around 500 */

for ( count = 0; count < 100; count++ )
    {
   if (( address = sbrk( -32000 )) == -1 )
      perror( "sbrk error" );
   printf( "sbrk return value on DECREASE %ld\n", address );
   }

sleep( 30 );           /* run ps on another screen, SZ same as before,
                          ( that is 500 )
                          is this right????? even though the value of
                          address gets smaller on each call to sbrk? */

Is there another way to find out the size of a process instead of using
ps? (could there be a bug in ps?)

Do I misunderstand something about how sbrk()/brk() malloc() and free()
are supposed to work?

Please send replies to :

yml at grebyn.com

Any suggestions, comments, hints, etc. will be GREATLY appreciated.

Thankyou in advance,

Yermo Lamers

Radix II Inc.
Oxon Hill Md.

yml at grebyn.com



More information about the Comp.unix.questions mailing list