1753401 Members
7194 Online
108792 Solutions
New Discussion

Re: system script

 
2ne1
Occasional Contributor

system script

In my unix / linux server  , there are always many process running in high CPU and use much memory , it makes the system run very slow .

Can advise if I would like to find it out , find and kill the processes which are

1) running over 3 hours with 90% CPU .
2) the process run over 12 hours

Can advise how can I write it ? or I guess these are very useful unix admin script , can advise where I can find the similiar one ?

Thanks.

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: system script

>there are always many process running in high CPU and use much memory, it makes the system run very slow.

 

Normally, it's your job to add more CPUs and memory to your machine, not kill arbitrary processes.

How do you know these processes are useless?

 

Take a look at the ps(1) output for the processes:

ps -ef

 

And look at the stime and time fields.

 

2ne1
Occasional Contributor

Re: system script

thx reply , I am not familiar with writing shell script , can advise what can I do ? Thanks.

Dennis Handly
Acclaimed Contributor

Re: system script

>I am not familiar with writing shell script, can advise what can I do?

 

If you execute the following ps(1) command you can get an entry for each process to make a decision.  Here is the

ps(1) output that may be helpful:

#     0          0 34-08:49:31    00:51 swapper          0.02
UNIX95=EXTENDED_PS ps -e -opid= -ouid= -oetime= -otime= -opcpu= -ocomm= |
while read pid uid etime otime pcpu comm; do
 #  echo "$pid $pcpu"   # debugging

   pcpu=${pcpu%.*}  # strip fractions
   if [ $pcpu -ge 90 ]; then
      echo "$pid is $pcpu %"
   fi
done