1753788 Members
7795 Online
108799 Solutions
New Discussion юеВ

Re: related process

 
ust3
Regular Advisor

Re: related process

thx reply ,

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
ust3
Regular Advisor

Re: related process

Actually , I want to kill BOT pid and ppid . Thx
ust3
Regular Advisor

Re: related process

sorry , I mean BOTH pid and ppid
Dennis Handly
Acclaimed Contributor

Re: related process

>but I still have question, the psid is only child process of pid, so from the below result, $3 is the pid (31694)

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.
ust3
Regular Advisor

Re: related process

thx reply,

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 .
Dennis Handly
Acclaimed Contributor

Re: related process

>the reason is the /tmp/process.list, the process id (58245,55874,5842,58745) in this file is not a pid

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
ust3
Regular Advisor

Re: related process

thx reply again,

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 .
Dennis Handly
Acclaimed Contributor

Re: related process

>But if I want to find the parent id of this ppid, can advise what can i do?

>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