- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- kill shell 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
Forums
Discussions
Discussions
Discussions
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
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
11-12-2003 03:12 AM
11-12-2003 03:12 AM
Example:
[sdatpp01][/home/root] #ps -ef | grep dsmc
root 12117 1 13 Nov 6 ? 40:01 dsmc sched
root 27781 23503 2 10:13:11 pts/0 0:00 grep dsmc
[sdatpp01][/home/root]
In this case I need to put the PID 12117 in a variable PID$
how do I do this in a script ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:13 AM
11-12-2003 03:13 AM
SolutionAttached.
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
11-12-2003 03:15 AM
11-12-2003 03:15 AM
Re: kill shell script
If you are looking to extract a PID from a ps listing, try this:
_PID=`ps -ef|grep $_STRING|tr -s " "|cut -d" " -f3`
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:17 AM
11-12-2003 03:17 AM
Re: kill shell script
Here's a sample of one of our kill scripts:
for PID in `ps -ef |grep web_command | grep -v grep |awk '{ print $2 }'`
do
kill -9 $PID
echo "web_command.ksh stopped"
done
Note that the usage of kill -9 is not recommended because it does not allow for the normal housekeeping when a process terminates and may leave memory allocated, etc, etc.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:24 AM
11-12-2003 03:24 AM
Re: kill shell script
Round here we like to give things chance to die first.
Instead of
kill -9 ${PID}
we would have
for sig in 1 2 3 15 9
do
kill -${sig} {PID} 2>/dev/null
done
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:24 AM
11-12-2003 03:24 AM
Re: kill shell script
you need field #2 in the ps output.
ps -ef | grep jobname | grep -v grep | awk '{print $2}'
field #3 is the parent process.
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:29 AM
11-12-2003 03:29 AM
Re: kill shell script
True, it's brutal but it's a shutdown script for an unimportant process (and I did note that it's not recommended). Since we're shutting down anyway, why would I care? In other circumstances you method would be much more appropriate.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:36 AM
11-12-2003 03:36 AM
Re: kill shell script
What do you think, if the process listens to kill -3, should be better, right?
Well, early bird catches the worm. I was thinking to long. ;-) grumble mumble..
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:44 AM
11-12-2003 03:44 AM
Re: kill shell script
What I think is that when I'm shutting down, I don't care what happens to the process. I don't care if it shuts down gracefully and release any memory regions and cleans up after itself. I'm shutting down, not worrying about etiquette or hurting a process's feelings. I want the damn thing to die and die now.
Other processes (like the database, for example) I obviously want to shut down normally but trivial ones like this I don't care about. The whole point here was to answer Brent's original question about getting the PID.
End of subject - please.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2003 03:47 AM
11-12-2003 03:47 AM
Re: kill shell script
I totally agree with you. It doesnt matter. I am talking about ending a process which is running in the backgound and stopping it with -9 might hurt in cases like disk defrag. That was not meant to critisize you in any way. ;-)
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2003 01:36 AM
11-13-2003 01:36 AM
Re: kill shell script
If you want to kill all processes related to a specific user we set up the following..
# killit /usr/local/bin/killit
# ESU#3 - Systems and Networking
# rcm(10/03/2001)
# this script was written to kill hung users
#
#==============================================
# BEGIN SCRIPT
ps -ef |grep -v -f /usr/local/bin/patt.1 |grep $1 > temp.1
kill -9 `awk '{print $2}' temp.1`
rm temp.1
# END SCRIPT
#==============================================
note ** /usr/local/bin/patt.1 file contains patterns that you want to avoid. it allows you to exclude items that you want to avoid killing..