Command to know all the Current running process and how to kill

All,

1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process)

2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX.

Kindly help.

Thanks,
SKP

Is this a homework assignment? (If so, please see Rules for Homework & Coursework Questions Forum and repost in the Homework & Coursework Questions Forum. Otherwise, please explain where these questions came from.)

Hello skp,

Welcome to forums,for your request. Following is an example which I have created for finding a java service you can search accordingly the processes and put it in condition highilighted, also this command only print the output,
if you are happy with command's output you can use it.

ps -ef | grep -v grep | awk -vs1=$(whoami) '{if($1== s1 && $9 == "docbase_name") {print $0}}' | awk '($3==1){a=a?a OFS $2:$2} ($3 != 1){b[$2]=$2;next} END{for(i in b){val=b OFS val}; print "kill -9 "val OFS a "\n"}' OFS=" " ORS=" "

Here I have put a process name which has in it docbase_name in it for 1st and 9th column, you can check man ps for same too.

Thanks,
R. Singh

Dear Don Cragum,
No.this is not homework...I am experienced professional but new to unix production support....So i just wanted to know the command..

I know ps-ef (To know all processes) and kill -9 pid(kill the process id)...

What i need the help from is

1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process)

2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX.

Thanks,
Sumanta

You can kill a process group leader and all of its descendants (at least those that have not become process group leaders on their own) by finding the process ID (PID) of the process group leader (using ps ) and then sending a signal to that PID with a leading minus sign (using kill ).

Note that unless you are running with elevated privileges, you won't be able to kill processes started by anyone but yourself.

Note also that using kill -9 attempts to terminate threads without giving them any chance to clean up what they were working on. This may be what you want, but it might also leave temporary files around that could have been cleaned up by a process before it terminated if it had been sent a SIGTERM signal instead of a SIGKILL signal.

Dear RavinderSingh13,

Thank you. Let us say i have below process details...If i write dymanically based on the query you have provided will it be works..
Kindly please advise.Thank you.

Example-
Parent Process 1
Child Process 11
Subchild Process 111

Parent Process 2
Child Process 22
Subchild Process 222

1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process)

ps -ef | grep -v grep | awk -vs1=$(whoami) '{if($1== s1 && $9 == "parent process name") {print $0}}' | awk '($3==1){a=a?a OFS $2:$2} ($3 != 1){b[$2]=$2;next} END{for(i in b){val=b OFS val}; 

2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX.

kill -9 "val OFS a "\n"}' OFS=" " ORS=" "

Hello skp,

Could you please try the following command which will only print the process ids in an order to kill (from child to parent ids) which is recomended as if we will kill parent before child it will create defunct processes. Also please don't try to use the command to kill processes, kindly validate it first as I don't have box to work on as of now, so I have not tested it.

 ps -ef | grep -v grep |  awk '{if($3!=1 && NR>1){X[$3]=X[$3]?X[$3] OFS $2:$2}} END{for(u in X){print "kill " X OFS u}}'

Also you can grep for specific process too in the command but as a first step could you please try same and let us know if this helps or any issues you face with this, please provide os details you are working on.

Thanks,
R. Singh

The answer to your first question depends on the system you are using. On e.g. linux,
-H will show a process tree of children and grandchildren. They are connected through PID and PPID (parent PID).

On (Free)BSD, ps has different options: