- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: user process
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
тАО01-09-2008 01:21 AM
тАО01-09-2008 01:21 AM
$vi pid_file
15484
4521
now I would like to have a script to kill all process , I would like to use the command "kill" first , if can't kill it , then use "kill -1" , if still can't then use "kill -3" , if still not then send mail to administrator , can advise what can i write the script ? thx .
Solved! Go to Solution.
- Tags:
- kill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 01:33 AM
тАО01-09-2008 01:33 AM
Re: user process
Read file under script and use kill process under case structure with default case to sendmail. Use echo $? to check id process is killed or not and then accordingle proceed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 01:38 AM
тАО01-09-2008 01:38 AM
Re: user process
try this:
if -z pid_file
then
for i in `cat pid_file`
do
kill $i
done
fi
if -z pid_file
then
mailx ....
fi
or this:
kill $(ps -fu
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 01:48 AM
тАО01-09-2008 01:48 AM
Re: user process
Here is a command with arguments which kill all user process at a glance
#ps -ef | awk '{print $1" "$2}' | grep
be careful to use this command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-09-2008 02:48 AM
тАО01-09-2008 02:48 AM
Solutionfor PID in $(< pid_file); do
kill -0 $PID 2> /dev/null
if [ $? -ne 0 ]; then
echo "PID $PID is not alive"
continue
fi
echo kill $PID
false # remove after script tested
if [ $? -eq 0 ]; then continue; fi
echo kill -INT $PID
if [ $? -eq 0 ]; then continue; fi
echo kill -QUIT $PID
if [ $? -eq 0 ]; then continue; fi
echo mailx -s "Problem killing process" root <
EOF
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 12:24 AM
тАО01-14-2008 12:24 AM
Re: user process
I am trying the script
for PID in $(< pid_file); do
kill -0 $PID 2> /dev/null
if [ $? -ne 0 ]; then
echo "PID $PID is not alive"
continue
fi
echo kill $PID
false # remove after script tested
if [ $? -eq 0 ]; then continue; fi
echo kill -INT $PID
if [ $? -eq 0 ]; then continue; fi
echo kill -QUIT $PID
if [ $? -eq 0 ]; then continue; fi
echo mailx -s "Problem killing process" root <
EOF
done
But I found the process only run the first part
echo $PID
kill -0 $PID 2> /dev/null
if [ $? -ne 0 ]; then
echo "PID $PID is not alive"
continue
fi
what I want is if the parocess is not killed , then run kill -1 , then kill -3 , if still not , then send me a mail , please help again. thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 12:52 AM
тАО01-14-2008 12:52 AM
Re: user process
kill -0 $PID 2> /dev/null
if [ $? -ne 0 ]; then
echo "PID $PID is not alive"
continue
fi
If it only does this, then that PID doesn't exist.
>what I want is if the process is not killed, ...
That part is there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 01:30 AM
тАО01-14-2008 01:30 AM
Re: user process
I tried the script , it try to kill the PID , but if it fail to kill , it pop the message PID is not alive , it works fine , but it seems not try to kill again by kill -1 , it seems the script is stopped at that time , and do not run the rest part of it (eg. if [ $? -eq 0 ]; then continue; fi
echo kill -INT $PID) , can advise what is wrong ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 01:55 AM
тАО01-14-2008 01:55 AM
Re: user process
The "kill -0", doesn't kill it, it checks the PID existance.
>but it seems not try to kill again by kill -1, it seems the script is stopped at that time
If the PID isn't there, it does no good to try to kill it.
To prove this, you could add: ps -fu $PID
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-14-2008 09:49 PM
тАО01-14-2008 09:49 PM
Re: user process
I have problem to use kill -0 to check the existence of pid , can advise if I want to skip this checking , what I want is to kill the pid by kill -1 first , if can't then kill -2 , then kill -3 , can advise can can I modify it? thx
how to skip the below part from the script
==========================================
kill -0 $PID 2> /dev/null
if [ $? -ne 0 ]; then
echo "PID $PID is not alive"
continue
fi