- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: how to kill all process by a script
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
тАО07-15-2010 07:37 AM
тАО07-15-2010 07:37 AM
how to kill all process by a script
#ps -ef | grep compress.sh |wc -l
500
I want to kill all the 500 process and release memory in HP UX server
- Tags:
- kill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 07:43 AM
тАО07-15-2010 07:43 AM
Re: how to kill all process by a script
So you have 500 processes with the name 'compress.sh' and you want to kill all of them?
# PIDS=$(UNIX95= ps -C compress.sh -opid=)
# kill ${PIDS}
This will find only processes named 'compress.sh'; capture the corresponding pid in a list in the PIDS variable and kill those processes.
Note the use of 'UNIX95=' with whitespace before the 'ps' command and without any semicolon. This arms the UNIX95 (XPG4) behavior only for the duration of the command line.
Using the UNIX95 '-C
Regards!
...JRF...
- Tags:
- UNIX95
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 08:07 AM
тАО07-15-2010 08:07 AM
Re: how to kill all process by a script
can i use xargs kill -15 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 08:11 AM
тАО07-15-2010 08:11 AM
Re: how to kill all process by a script
> how can i kill using ps command in a single line ?
# kill $(UNIX95= ps -C compress.sh -opid=)
...or if you need:
# kill -9 $(UNIX95= ps -C compress.sh -opid=)
The advantage to first capturing the list and then issuing the 'kill' is that you can build the list once and apply successively harder hammers:
# kill -hup ${PIDS}
# kill -term ${PIDS}
# kill -9 ${PIDS}
Use the 'kill -9' only as a last resort.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 12:36 PM
тАО07-15-2010 12:36 PM
Re: how to kill all process by a script
You can use any switch you want, start with the default, and work your way up to -9.
Try 15 if you you want.
If the -9 tries to kill the init process, process ID 1, nothing bad should happen, the request should be ignored. On unstable systems, I've seem entire systems suddenly implode.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 01:42 PM
тАО07-15-2010 01:42 PM
Re: how to kill all process by a script
> SEP: You can use any switch you want, start with the default, and work your way up to -9. Try 15 if you you want.
A 'kill' without a switch defaults to 'kill -15' which is a SIGTERM or 'kill -TERM'.
In the case of daemons, a standard practice is for the daemon to re-read its configuration file or otherwise re-initialize itself when it receives a HANGUP signal ('kill -HUP').
Some signals can be trapped, which means that the program receiving them has the ability to ignore or invoke a signal handler (a short block of code) to perform some specific action like removing temporary files before exiting.
A 'kill -KILL' ('kill -9') *cannot* be trapped. That is, there is nothing that a program can do to ignore it nor to invoke any signal handler. Using this capriciously may cause programs to leave temporary files lying about (or worse) leave shared memory segments orphaned and holding precious memory. Using a 'kill -9' with an 'fbackup' session represents a classic case.
A 'kill -0' ('kill -NULL') can be used to test a pid's validity,
> SEP: If the -9 tries to kill the init process, process ID 1, nothing bad should happen, the request should be ignored. On unstable systems, I've seem entire systems suddenly implode.
As far as I know, a 'kill -9 1' (which is an untrappable kill of the init daemon (pid=1)) is a "might-as-well-reboot". Daemons have 'init' as their parent process so terminating 'initd' terminates those.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 05:38 PM
тАО07-15-2010 05:38 PM
Re: how to kill all process by a script
You shouldn't worry about this. Your bosses don't pay you by the line. :-)
If you're scripting, it is better to be more understandable.
>JRF: As far as I know, a "kill -9 1" is a "might-as-well-reboot".
No, kill(2) says it will NOT honor a SIGKILL for PID 1:
pid can equal 1 unless sig is SIGKILL or SIGSTOP.
So SEP was right about it being ignored.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2010 08:40 PM
тАО07-15-2010 08:40 PM
Re: how to kill all process by a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-16-2010 01:47 AM
тАО07-16-2010 01:47 AM
Re: how to kill all process by a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-16-2010 08:51 AM
тАО07-16-2010 08:51 AM
Re: how to kill all process by a script
> Dennis: kill(2) says it will NOT honor a SIGKILL for PID 1...
So SEP was right about it being ignored.
Ah, thank you for the correction. Yes, SEP was right. The manpages for kill(1) infer this but the manpages for kill(2) clearly state this as you noted. I stupidly failed to read the section-2 pages :-(
Regards!
...JRF...