- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: pkill equivalent?
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
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
тАО03-19-2007 08:00 AM
тАО03-19-2007 08:00 AM
What is the hp-ux equivalent of sun's pkill? I cannot find pkill anywhere on the 11.23 system.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 08:09 AM
тАО03-19-2007 08:09 AM
Re: pkill equivalent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 08:10 AM
тАО03-19-2007 08:10 AM
Solution#!/usr/bin/sh
COMM=${1}
shift
UNIX95=1 ps -C ${COMM} -o pid='' | while read P
do
kill -15 ${P}
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 08:12 AM
тАО03-19-2007 08:12 AM
Re: pkill equivalent?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 08:15 AM
тАО03-19-2007 08:15 AM
Re: pkill equivalent?
There isn't a direct counterpart. However, you can/should leverage the UNIX95 behavior of 'ps' to find a process by name :
# UNIX95= ps -C cron -o pid=
For example, the above will return the 'pid' of the 'cron' daemon. The match is *exactly* to the basename of a process and no other. The '-o pid=' signifies that all you want shown is the 'pid'(s) of processes by the name of the '-C' switch's argument.
The equal sign after the 'pid' argument means suppress the heading line from 'ps'.
There is a space (or tab) after UNIX95=. This limits the UNIX95 behavior to the command line only.
Given that you find the correct pid for the correct process, you can proceed to gently 'kill' the process. That is, begin with a simple 'kill -hup' and then a 'kill -term' and *only* as a last resort, a 'kill -9'. Remember that at 'kill -9' cannot be trapped and may leave shared memory segments and/or temporary files abandoned!
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 06:58 PM
тАО03-19-2007 06:58 PM
Re: pkill equivalent?
#!/usr/bin/sh
#pkill - kill processes matching pattern
prgName=$(basename $0)
TMPFILE=/tmp/$prgName.$$
syntax()
{
cat << EOH
Usage:
pkill [-p] [-s sig] pattern
Description:
Kill all processes in output of 'ps -ef' that match pattern.
Options:
-p Match pattern only to process names (use output
of 'ps -e').
-s sig Send this signal; if not specified, -9 is used
EOH
exit
}
unset procs_only
sig=-9
while getopts ps: opt ; do
case $opt in
p) procs_only=TRUE ;;
s) sig=$OPTARG ;;
*) syntax ;;
esac
done
shift $(( $OPTIND-1 ))
[ -z "$*" ] && syntax
if [ -n "$procs_only" ] ; then
ps -e | grep "$*" | nl -s":" > $TMPFILE
else
ps -ef | grep "$*" | egrep -v "grep|$prgName" > $TMPFILE
fi
if [ -s $TMPFILE ] ; then
sed 's/ / /g' $TMPFILE
echo "Send kill $sig? Press [Ctl][C] to abort, [Enter] to procede >\c"
read a
cat $TMPFILE | awk '{ print $2 }' | xargs kill $sig
else
echo "$prgName: \"$*\" no matching processes found."
fi
rm $TMPFILE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 07:04 PM
тАО03-19-2007 07:04 PM
Re: pkill equivalent?
pkill "this|that|the_other"
-Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 07:34 PM
тАО03-19-2007 07:34 PM
Re: pkill equivalent?
>Eric: my script would be better if it piped ps through egrep instead of grep.
pkill "this|that|the_other"
There is no reason to use an egrep hammer for this. Unless you want that interface in your script. (It appears you might.)
You can simply use: grep -e this -e that -e the_other
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-19-2007 08:03 PM
тАО03-19-2007 08:03 PM
Re: pkill equivalent?
http://www.hpux.ws/gkill
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com