Linux / UNIX Tech Support Forum
This is a discussion on Script To Kill process if time and memories of more than 30% within the Shell scripting forums, part of the Development/Scripting category; Hello. The script which kills processes which occupy processor time and memories of more than 30% ( for example ) ...
|
|||||||
| Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hello. The script which kills processes which occupy processor time and memories of more than 30% ( for example ) is necessary to me. I ask the help.
|
| Sponsored Links | ||
|
|
|
||||
|
There is no command exits which can give you ready to use output, however shell pipes can be used along with ps command. To know the top 10 memory consuming process use the following commands:
Code:
ps auxf | sort -nr -k 4 | head -10 Code:
ps auxf | sort -nr -k 3 | head -10 Code:
ps auxf | sort -nr -k 4 | head -10 | awk '{ if ( $4 > 30) print $1}'
Code:
P=$(ps auxf | sort -nr -k 4 | head -10 | awk '{ if ( $4 > 30) print $1}')
killall $P
__________________
Vivek Gite Linux Evangelist |
|
|||
|
Thank, very mach
Code:
#!/bin/bash
max_cpu=$(ps -eo user,pid,pcpu,pmem --no-headers | awk '{ if ( $3 > 30) print $2}')
max_mem=$(ps -eo user,pid,pcpu,pmem --no-headers | awk '{ if ( $4 > 10) print $2}')
echo $max_cpu
echo $max_mem
kill -9 $max_mem
kill -9 $max_cpu
Last edited by nixcraft; 20-04-2009 at 12:51 PM. |
|
|||
|
now there are a couple of new requirements to the program.
1.chtoby program to monitor the process continuously 2.imena users who are not subject to the control 3.nabor process ID to be ignored 4. a signal sending process 5.kuda output logs (default is standard output, or in a specified file) 6. on a parameter monitor process who can help, it is simply oromnoe thanks =) |
|
|||
|
now there are a couple of new requirements to the program.
1. program to monitor the process continuously 2. the names of the users who are not subject to the control 3. set of identifiers to be ignored 4. a signal sending process 5. where to put logs (default is standard output, or in a specified file) 6. on a parameter monitor process who can help, it is simply oromnoe thanks =) |
|
||||
|
Use cron jobs to run script every 5 min.
You can use grep to filter out certain users. ???? ??? Quote:
??? ??? === explains in more details...
__________________
Vivek Gite Linux Evangelist |
|
|||
|
3 is a view that there is a list of PID, which would ignorirovatsya program and will not be killed
4 a signal is transmitted to a process which should be killed (one of the signals that kill - 9) 6 on a parameter will kill the process (excessive use of memory or processor) All items must be combined into one script |
|
|||
|
Use the commands you already got to place all heavy consumers in a file containing all data relevant to you like: name|pid|users.Process this file with a set of sed -i -e "/to_remove/d" $process_list_file. Define a config file containing the desired exceptions in variable ( excluded_users="john doe jane rex" for eg ) and include it in your script.Use for loops to get rid of them from the file.Extract from what's left the relevant info(pid?) and send it to kill.
|
![]() |
| Tags |
| awk , kill , killall , linux , pkill , shell scripting , unix |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell script to kill process Automatically after 3 days | darknet | Shell scripting | 4 | 02-11-2009 12:40 AM |
| Killing of a process and send a mail if the process doesnot come up within 2 minutes | Prince89 | Shell scripting | 1 | 11-02-2008 12:39 PM |
| kernel panic -not syncing attempt to kill init | jhn_daz@yahoo.com | Linux software | 3 | 26-11-2007 04:16 PM |
| Activate NIC at boot time | lacloai | Linux software | 5 | 13-10-2007 07:10 PM |
| iptables -m time | Joe | Linux software | 1 | 14-03-2006 12:53 PM |