Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!ihnp4!twitch!homxb!dean From: dean@homxb.UUCP (D.JONES) Newsgroups: comp.unix.questions Subject: Re: Determining system memory Message-ID: <1574@homxb.UUCP> Date: 1 Apr 88 18:35:55 GMT References: <248@lxn.UUCP> <1271@PT.CS.CMU.EDU> Organization: AT&T Bell Laboratories, Holmdel Lines: 25 Summary: sbrk(), ulimit() In article <1271@PT.CS.CMU.EDU>, edw@IUS1.CS.CMU.EDU (Eddie Wyatt) writes: > > I have been trying to find a nice, clean way to determine system > > memory under SYS V 2.2. I have come up with two solutions to this > > problem. However, there must be a cleaner/faster way :-). > > Any other solutions are welcome (especially those that are faster :-) > If what you are really interested in is the memory currently available > to a given process I suggest using sbrk. sbrk memory > in fix block sizes until sbrk fails. > Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu Now you know how much memory you have for the current process, but do you have to sbrk() it back if you are going to use malloc() ??? A call to ulimit() on SysV 2.2 with an arg of 3 will return the max brk value for the current process. What about something like: long memavail() { return(ulimit(3) - (long)sbrk(0)) } It looks like this will work on our SunOS 4.0 machines also. I'm Just starting to get into this UNIX stuff, don't flame me if this is a bozo idea... Dean S Jones AT&T Gateways!homxb!dean