Xref: utzoo comp.unix.sysv386:3594 comp.unix.programmer:789 comp.unix.questions:27797 Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!wuarchive!rice!uupsi!grebyn!yml From: yml@grebyn.com (Yermo M. Lamers) Newsgroups: comp.unix.sysv386,comp.unix.programmer,comp.unix.questions Subject: SCO Unix 3.2 brk()/sbrk() problems???? Message-ID: <24408@grebyn.com> Date: 2 Jan 91 16:36:12 GMT Reply-To: yml@grebyn.UUCP (Yermo M. Lamers) Followup-To: comp.unix.sysv386 Organization: Grebyn Timesharing, Vienna, VA, USA Lines: 63 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@grebyn.com Any suggestions, comments, hints, etc. will be GREATLY appreciated. Thankyou in advance, Yermo Lamers Radix II Inc. Oxon Hill Md. yml@grebyn.com