- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Simple Script Help
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
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-29-2005 11:46 PM
11-29-2005 11:46 PM
#ps -ef | grep exec
root 25098 1 0 01:00:01 ? 00:00:00 /usr/lib/mail/execmail root
How can I pull out the pid and kill it?
Also I want to kill all processes by a specific user named mmdf, like;
# ps -fu mmdf
mmdf 25057 265 0 01:00:00 ? 00:00:00 sh -c /usr/mmdf/bin/cleane
mmdf 16861 25063 4 07:11:50 ? 00:01:02 submit
mmdf 25063 25057 1 01:00:00 ? 00:22:28 /usr/mmdf/bin/cleanque
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 11:56 PM
11-29-2005 11:56 PM
SolutionUse the UNIX95 (XPG4) form of 'ps' to find your processes by name:
Suppose I want to look for a 'sleep' process owned by root:
# PID=`UNIX95= ps -e -o pid,user,comm|awk '$2~/root/ && $3~/sleep/ {print}'`
Then:
# if [ -z "${PID}" ]; then
> kill -1 ${PID} 2>/dev/null
> sleep 3
> kill -15 ${PID} 2>/dev/null
> sleep 3
> kill -9 ${PID} 2>/dev/null
> fi
The above does more and more brutal kills. If the process dies along the way, the redirection of STDERR eliminates seeing the "non-existent process" message.
The last point is never to do a 'kill -9' except as a last restort. A 'kill -9' cannot be trapped by a process leaving it no opportunity to free shared memory and/or remove any temporary files.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 11:56 PM
11-29-2005 11:56 PM
Re: Simple Script Help
A few ways to go. hopefullly there is something unique about the process.
Lets say we want to kill a process named execmail
PID=$(ps -ef | grep execmail | grep -v grep| awk '{print $2}'
kill $PID
SEP
You may need
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-29-2005 11:57 PM
11-29-2005 11:57 PM
Re: Simple Script Help
#for i in `cat /tmp/kill_list`
do
kill $i
sleep 1
kill -9 $i
done
Same thing for a particular user.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2005 11:59 PM
11-29-2005 11:59 PM
Re: Simple Script Help
Also, note carefully that I wrote:
# UNIX95= ps ...
There is a blank (space) character after the UNIX95= but *before* the 'ps'. This limits the setting of the UNIX95 (XPG4) behavior to the command line on which it appears. You don't want this setting to influence other commands without your explicit choice!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 12:18 AM
11-30-2005 12:18 AM
Re: Simple Script Help
One correction. I should have said "... print $1)'` as:
# # PID=`UNIX95= ps -e -o pid,user,comm|awk '$2~/root/ && $3~/sleep/ {print $1}'`
This builds a list of 0 to n process IDs and allows seeking and killing in one pass.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 12:19 AM
11-30-2005 12:19 AM
Re: Simple Script Help
PID=$(ps -ef | grep execmail | grep -v grep| awk '{print $2}'
Needs to be
PID=$(ps -ef | grep execmail | grep -v grep| awk '{print $2}')
A minor but potentially disasterous problem.
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-30-2005 12:27 AM
11-30-2005 12:27 AM
Re: Simple Script Help
see also the thread for the question that i had recently posted:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=969402
hope this helps too!
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 01:57 AM
11-30-2005 01:57 AM
Re: Simple Script Help
The good news is that ps can perform an exact match for a process name, user and group ID, and eliminate potentially critical mistakes. For your first example:
UNIX95=1 ps -C execmail -o pid,ruser,args
will only find processes exactly named execmail (not rexecmail22 and other variations). Using the -o options helps to limit the required items of data. You can eliminate the title line for scripting by setting the label to null (-o pid= -o ruser= -o args=)
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2005 02:49 AM
11-30-2005 02:49 AM
Re: Simple Script Help
I think grep can be made safe but...arguing with BH is a sure way to lose an argument.
searchstring=$1
# make first input parameter the search string.
PID=$(UNIX95=1 ps -C $searchstring -o pid= -o ruser= -o args= | awk '{print $1}')
kill $PID
I also recommend not allow search parameters like root.
Safer.
BH approved?
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com