[comp.unix.questions] Changing CPU limits

lauri@mitre-bedford.arpa (Lauri A. Szklut) (03/23/88)

It appears that ULTRIX determines the cpu limit for a process at process
creation.  I can use the "limit" command to change my cpu limit for the
current process (csh) and any future processes.  My question:  is there 
a way to modify this limit once the process is already running?  Then if a 
process I had running in the background was approaching its cpu limit, I 
could up the limit and avoid having to restart the process from scratch.  
Any ideas would be appreciated.  Thanks.

Lauri Szklut
DEC Systems Software
MITRE Corporation
E-mail: lauri@mitre-bedford.arpa

edw@IUS1.CS.CMU.EDU (Eddie Wyatt) (03/23/88)

 > It appears that ULTRIX determines the cpu limit for a process at process
 > creation.  I can use the "limit" command to change my cpu limit for the
 > current process (csh) and any future processes.  My question:  is there 
 > a way to modify this limit once the process is already running?  Then if a 
 > process I had running in the background was approaching its cpu limit, I 
 > could up the limit and avoid having to restart the process from scratch.  
 > Any ideas would be appreciated.  Thanks.

    {
    struct rlimit rlp;

    getrlimit(RLIMIT_CPU,&rlp);
    rlp.rlim_cur = rlp.rlim_max;
    setrlimit(RLIMIT_CPU,&rlp);
    }

This will set the cpu limit to the hard limit (can't go high unless your root).


-- 

Eddie Wyatt 				e-mail: edw@ius1.cs.cmu.edu

lm@arizona.edu (Larry McVoy) (03/23/88)

In article <12569@brl-adm.ARPA> lauri@mitre-bedford.arpa (Lauri A. Szklut) writes:
>
>It appears that ULTRIX determines the cpu limit for a process at process
>creation.  I can use the "limit" command to change my cpu limit for the
>current process (csh) and any future processes.  My question:  is there 
>a way to modify this limit once the process is already running?  

You may trap SIGXCPU and/or SIGXFSZ and continue (or so the man page for
getrlimit(2) seems to imply).  Better yet, why not just crank up the 
limits at startup time if you know that it's going to overflow?  
setrlimit(2) will tell you how.
-- 

Larry McVoy	lm@arizona.edu or ...!{uwvax,sun}!arizona.edu!lm