- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script to kill dead and old user processes
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2009 08:18 AM
тАО12-07-2009 08:18 AM
Script to kill dead and old user processes
I need some script help. I am in need of a script that can accomplish the following:
- find a particular process (a known process run by multiple users) that is over say 24 hours old and execute a kill.
- find user processes (would be same as above process type) that are older than several hours that are consuming over 90% CPU and kill them.
- build in some safety nets in place to prevent killing processes that are needed (like active sessions)
Any assistance is appreciated. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2009 08:21 AM
тАО12-07-2009 08:21 AM
Re: Script to kill dead and old user processes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2009 08:59 AM
тАО12-07-2009 08:59 AM
Re: Script to kill dead and old user processes
Since you know the process name, find it (or them) by name using the XPG4 option of 'ps':
# UNIX95= ps -C vxfsd -o pid= -o uid= -o time= -o tty= -o comm=
The "=' character suppresses the heading. In the above, you would be returned the pid of the process named "vxfsd" along with the processes's effective owner, the elapsed time, the controlling terminal and the command name.
These five fields should allow you to skip "system" processes (e.g. those with a 'uid' less than, for example 100 -- a convention) and/or those not associated with a terminal.
Your script can then parse these field values and use the pid for a kill.
I advise you to issue a 'kill -hup' followed by a simple 'kill -term' and finally only as a last restort, a 'kill -9' if you must terminate. This gives a process an opportunity to cleanup temporary files and shared memory segments.
If you are running 11.31, then take a look at 'pkill(1).
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2009 09:04 AM
тАО12-07-2009 09:04 AM
Re: Script to kill dead and old user processes
> oh, just a note...the "dead" processes will not necessarily show up as "defunct". Thanks.
That matters not. An entry in the process table that is marked as "defunct" is a zombie. Since zombie's are already dead (with only a process table entry yet to be reaped by its parent) they can't be killed.
You might want to include the parent pid ('ppid') in your process table selection. Seeing a parent process pid=1 (for 'initd') might help indicate a "dead" process in your environment --- assuming that your application doesn't daemonize itself.
Regards!
...JRF...
- Tags:
- zombie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2009 11:39 PM
тАО12-07-2009 11:39 PM
Re: Script to kill dead and old user processes
Sorry to post my query in other user post.
Regarding your last point in the last repy
>> Seeing a parent process pid=1 (for 'initd') might help indicate a "dead" process in your environment
# UNIX95= ps -C tnslsnr -o pid= -oppid= -o uid= -o time= -o tty= -o comm=
14348 1 103 00:00:30 ? tnslsnr
#
The PPID of the Oracle listner is "1" (init),and the process is active currently.
Could you please flash more light on this.
Thanks
Aneesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-08-2009 02:28 AM
тАО12-08-2009 02:28 AM
Re: Script to kill dead and old user processes
Zombies can be killed by killing the zombie master, parent.
>Aneesh: The PPID of the Oracle listner is "1" (init) and the process is active currently. Could you please flash more light on this?
This may be the case of the listener making itself a demon.
Or when the parent dies, init adopts/reaps the children.
- Tags:
- zombie master