LONG Psetlimit( WORD lim, LONG value );
1: get/set maximum CPU time for process (in milliseconds) 2: get/set total maximum memory allowed for process 3: get/set limit on Malloc'd memory for process
If value is negative, the limit is unchanged; if value is 0, the corresponding resource is unlimited; otherwise, the resource limit is set to value.
Setting the "maximum memory" limit means the process is not allowed to grow bigger than that size overall. Setting the "maximum Malloc'ed" limit means that the process may allocate no more than that much memory. The difference is that the latter limit applies above and beyond the text+data+bss size of the process.
Using Psetlimit sets the corresponding limit for both the process and any children it creates thereafter. Note that the limits apply to each process individually; setting the child CPU limit value to 1000 and then using fork(2) to create three children results in each of those children getting a CPU limit value of one second. They do not have a collective or sum total limit of one second.
There is no restriction on increasing a limit. Any process may set any of its limits or its childrens' limits to a value greater than its current limit, or even to zero (unlimited).
Memory limits do not apply during execution of Pexec; that is, if a process is limited to (say) 256KB of memory, it can still exec a child which uses more
Memory limits are not retroactive: if a process owns 256KB of memory and then calls Psetlimit to restrict itself to 128KB, it will not be terminated, but no Malloc calls will succeed until its size drops below 128KB.
CPU limits are retroactive, however: if a process has used three CPU seconds and calls Psetlimit to restrict itself to one second, it will immediately receive SIGXCPU and terminate.
To alleviate this, the parent must create a child process via Pvfork, and this process (which hasn't consumed any CPU time yet) must call Psetlimit and then Pexec to create the child that is meant to be limited.