- 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
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2008 09:54 PM
01-14-2008 09:54 PM
Re: user process
You can just remove this "kill -0 if ... fi" block of code. But you'll get a mail message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2008 10:19 PM
01-14-2008 10:19 PM
Re: user process
I am not understand what is the use the that part of script
===========================================
kill $PID 2> /dev/null
if [ $? -eq 0 ]; then continue; fi
===========================================
is it mean ?
if it fail to kill the PID , then its output = 0 , then do next loop kill -INT ?
but in my mind , the logic should be if it is successful kill PID , the output should be = 0 , that should not go to next loop .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2008 10:35 PM
01-14-2008 10:35 PM
Re: user process
kill $PID 2> /dev/null
if [ $? -eq 0 ]; then continue; fi
>if it fail to kill the PID, then its output = 0, then do next loop kill -INT?
If kill works, its exit status is 0 and then it continues to the next iteration of the loop.
(This is goto/break/continue logic, not scummy nested if.)
>the logic should be if it is successful kill PID, the output should be = 0, that should not go to next loop.
It doesn't go to the next kill -INT but does the next PID.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2008 01:38 AM
01-17-2008 01:38 AM
Re: user process
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
I tried the script , I hve edit the pid_file , some of pid are exist and some are non-exist , but when the script , it shows are pid is not alive .
PID 58745 is not alive
PID 15645 is not alive
PID 87852 is not alive
PID 15645 is not alive
PID 14454 is not alive
while PID 15645 is exist in my system , can advise what is wrong ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2008 01:46 AM
01-17-2008 01:46 AM
Re: user process
kill -0 15645 , the result is "Operation not permitted" .
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2008 07:44 PM
01-17-2008 07:44 PM
Re: user process
Something wrong here. I don't get that on HP-UX. You may get "permission denied".
And if these are the same, it means you need to be root to kill that process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2008 11:41 PM
01-17-2008 11:41 PM
Re: user process
if use root to kill -0 , it works, I would like to further ask , if there are many process in the file pid_file , some are of process are alive , some are not alive , the script will still kill the process are alive ?
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2008 11:48 PM
01-17-2008 11:48 PM
Re: user process
Yes. But if your file has data from hours and days ago, you might kill the wrong process, because PIDs are eventually reused.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 12:32 AM
01-18-2008 12:32 AM
Re: user process
Yes. But if your file has data from hours and days ago, you might kill the wrong process, because PIDs are eventually reused -->
I will remove pid_file after it kill the process , the new pid_file will be generated if it is required to kill .
I would like to confirm you whether the logic is :
it first read all pid in pid_file (kill -0) , it try to kill it by "kill" , if successful to kill , then do nothing , if unsuccessful to kill , then try kill -INT , if still not success , then try kill -QUIT , if still not success , then mailx , is the logic correct ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 12:45 AM
01-18-2008 12:45 AM
Re: user process
>it first read all pid in pid_file (kill -0),
It reads them all in the shell but it does them one by one.
>it try to kill it by "kill", if successful to kill, then do nothing, if unsuccessful to kill, then try kill -INT, if still not success, then try kill -QUIT, if still not success, then mailx, is the logic correct?
Yes, if you remove those debugging "echo"s and one "false".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 01:53 AM
01-18-2008 01:53 AM
Re: user process
I am thinking how to test it , I hv try to use the script to kill the PID , it can kill all process I created , can advise if I want to test to kill a process that is "never be killed" that means it can not be killed , so that I can test the mail will be sent to me , can advise what pid like that ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 02:01 AM
01-18-2008 02:01 AM
Re: user process
I put those "false" calls there.
>can advise if I want to test to kill a process that is "never be killed" that means it can not be killed, so that I can test the mail will be sent to me, can advise what pid like that?
You can try PID 1, that can't be killed.
Or you could call signal for SIGINT and SIGQUIT and use SIG_IGN. (You can still use kill -KILL on that process.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 02:26 AM
01-18-2008 02:26 AM
Re: user process
I try to kill 1 , I know the process is not killed , but do not have any message , is there other process that i can test ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2008 02:46 AM
01-18-2008 02:46 AM
Re: user process
Are you root? If you aren't root, it will say you can't kill it, with that kill -0.
You can of course comment out the kill -0 so it goes to the mailx.