- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: related 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
12-06-2007 05:16 AM
12-06-2007 05:16 AM
related process
for i in `ls -l /tmp/process.list`
do
kill $i
done
the file is as below.
$vi /tmp/process.list
58245
55874
5842
58745 < -- all these are process
now , I not only want to kill the process in this list , I also want kill the related process ( all its child and parent process ) , I know I can find the process by "ps -ef" , can advise how to add "ps -ef" to my above script so that the related process can be killed ?
thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 05:24 AM
12-06-2007 05:24 AM
Re: related process
did you try:
pids=$(ps -ef | grep
kill -9 $pids
kind regards
yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 06:51 AM
12-06-2007 06:51 AM
Re: related process
kill -9 $pids
be carefull killing parents, is this realy wat you want?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 06:56 AM
12-06-2007 06:56 AM
Re: related process
for i in `ls -l /tmp/process.list`
do
for x in ` ps -ef | grep $i | awk '{print $2, $3}' `
do
echo kill $x
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 09:37 AM
12-06-2007 09:37 AM
Re: related process
for i in `ls -l /tmp/process.list`
do
for x in ` ps -ef | grep " "$i" " | awk '{print $2, $3}' `
do
echo kill $x
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 10:52 PM
12-06-2007 10:52 PM
Re: related process
for psid in `cat /tmp/process.list`
do
for psids in `ps -ef | grep $psid | awk '{ print $2, $3 }'`
do
kill -9 $psids
done
done
Rgds
-NKG-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2007 11:09 PM
12-06-2007 11:09 PM
Re: related process
So pls be care full while running this as this could kill ur init process.
And a small mistake could be fatel.
Or add "grep -v init" in above solutions.
BR,
Kapil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2007 12:40 AM
12-07-2007 12:40 AM
Re: related process
You can find the one process by: ps -fp PID
Kapil: So pls be careful while running this as this could kill your init process.
It won't let you cut your throat, kill(2):
pid can equal 1 unless sig is SIGKILL or SIGSTOP.
So it is init's job to handle the other signals.
>F Verschuren: one more safety to make sure your ps does not find a part of a process number:
Probably something like this:
for pid in $(< /tmp/process.list) ; do
echo kill $(UNIX95= ps -e -o pid= -o ppid= | grep -w $pid)
done
This won't kill any deeper than the child.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 05:08 PM
12-11-2007 05:08 PM
Re: related process
I think the below is fine , as your advice , I have two problem when kill the process , can help to advise the solution ,
1. if use the script to check other related process , I am afraid it will kill the process that init id is 1 or 0 , I think this is system process and should not be killed , can advise how to avoid this kind of process to be killed ? how to change the script to avoid kill this kind of process ?
2. As this script is run by user themself , if they killed process in /tmp/process.list , so they have killed the current login , so they can't kill the related process , can advise how to make sure they can kill the related process first ? Thx.
or psid in `cat /tmp/process.list`
do
for psids in `ps -ef | grep $psid | awk '{ print $2, $3 }'`
do
kill -9 $psids
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2007 06:41 PM
12-11-2007 06:41 PM
Re: related process
I mentioned this can't happen for init. (You might want to test this on a test system first. :-)
>2. As this script is run by user themselves, ..., can advise how to make sure they can kill the related process first?
Go back to my nohup suggestion:
http://forums12.itrc.hp.com/service/forums/questionanswer.do?threadId=1181073
Then take my suggestion and wrap it another $() and do one single kill:
nohup echo kill $(for pid in $(< /tmp/process.list) ; do
UNIX95= ps -e -o pid= -o ppid= | grep -w $pid
done)
Remove echo after you have checked it. You can check by:
$ xargs -n1 ps -fp < nohup.out | grep -v COMMAND | sort -u
(Ignore "ps: wrong PID number kill".)
(Remove echo after you have checked it.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 01:38 AM
12-13-2007 01:38 AM
Re: related process
Sorry to my stupid , the below script is OK , but I still have question , the psid is only child process of pid , so from the below result , $3 is the pid ( 31694)
the script :
or psid in `cat /tmp/process.list`
do
for psids in `ps -ef | grep $psid | awk '{ print $2, $3 }'`
do
kill -9 $psids
done
done
the result
31697 31694
1548 29714
but what I want to kill is ppid , I can find it by ps -ef | grep 31694 | awk '{ print $2, $3 }'` , this $3 is the ppid , if I want to kill this $3 , can advise how can I change the script ? Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 01:43 AM
12-13-2007 01:43 AM
Re: related process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 01:56 AM
12-13-2007 01:56 AM
Re: related process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 02:35 AM
12-13-2007 02:35 AM
Re: related process
You're going to have to have a picture. You need to explain why you think your script doesn't work.
Your script will kill the list of PIDs. And it will also kill their children and their parent.
It does that by first finding PID in PID field, and then killing both PID and PPID. If it finds in in the PPID field, it kills child and the PID again. (I assumed you didn't care that you killed some twice.)
So since I think it does what you want, you will need to explain what's missing by an example.
Note: should really be using my for/UNIX95= ps solution that correctly "greps" and even Bill will be happy. :-)
Basically use my script and that xargs checking script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 04:30 AM
12-13-2007 04:30 AM
Re: related process
You're going to have to have a picture. You need to explain why you think your script doesn't work.
--> the reason is the /tmp/process.list , the process id (58245,55874,5842,58745) in this file is not a pid , I can use the script to find the pid , and now want to have another script to find the ppid , the /tmp/process.list is generated from the another script .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 04:38 AM
12-13-2007 04:38 AM
Re: related process
PIDs are PIDs. :-)
>now want to have another script to find the ppid
To find a list of PPIDs for each PID in that file:
for pid in $(< /tmp/process.list); do
UNIX95= ps -p $pid -o ppid=
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 05:04 PM
12-13-2007 05:04 PM
Re: related process
Your script can find the ppid , it is OK.
for pid in $(< /tmp/process.list); do
UNIX95= ps -p $pid -o ppid=
done
But if I want to find the parent id of this ppid , can advise what can i do ? thx
ps. what I actucally want is the parent id of ppid in the /tmp/process.list .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2007 06:33 PM
12-13-2007 06:33 PM
Re: related process
>what I actually want is the parent id of ppid in the /tmp/process.list.
The file just has PIDs. I find the PPID of each PID in that file.
If you really want to go back one more:
for pid in $(< /tmp/process.list); do
UNIX95= ps -p $(UNIX95= ps -p $pid -o ppid=) -o ppid=
done