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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command to know all the Current running process and how to kill
# 1  
Old 12-29-2014
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

Last edited by skp; 12-29-2014 at 07:09 AM..
# 2  
Old 12-29-2014
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.)
# 3  
Old 12-29-2014
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.

Code:
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[i] 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

Last edited by RavinderSingh13; 12-29-2014 at 07:38 AM..
# 4  
Old 12-29-2014
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
# 5  
Old 12-29-2014
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.
# 6  
Old 12-29-2014
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)
Code:
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[i] 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.
Code:
kill -9 "val OFS a "\n"}' OFS=" " ORS=" "

# 7  
Old 12-29-2014
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 defunctprocesses. 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.
Code:
 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[u] 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Idle command to kill the process running n unx box machine

Hi Team , I have one process named as cec_analysiseool that is running on unix box machine now i want to kill this process so please advise what will be the ideal command to kill this , what i have tried is :confused: kill -9 `ps -ef | grep cec_analysiseool | grep -v grep | awk '{print $2}'` (2 Replies)
Discussion started by: unclesamm
2 Replies

2. Shell Programming and Scripting

List Process running under current user

Hi, i need to list the processes running only under current logged in user. EX: $ whoami oraaqw $ ps -ef | grep tnslsnr oraaqw 11403300 19267592 0 09:14:47 pts/3 0:00 grep tnslsnr oraaqw 15794208 1 0 Jan 14 - 11:59... (6 Replies)
Discussion started by: aravindadla
6 Replies

3. Shell Programming and Scripting

Script to kill a process running at a certain port

Hello, I have multiple scripts (vlc1, vlc2,...vlc5) and as I do not know how to run them as upstart processes, I entered my script links into rc.local file. Here is the sample one for process vlc1: $ nano /etc/rc.local added below line into rc.local /var/bin/./vlc1 & Port nr of vlc1... (7 Replies)
Discussion started by: baris35
7 Replies

4. Shell Programming and Scripting

Help with kill a specific process after certain running time

Hi, Do anybody experience to write a bash script in order to kill a specific process (java) after certain time of running? eg. java java.jar task_run.txt I will run a java program (java.jar) which will run a long list of process (task_run.txt) one by one. I plan to terminate the java... (5 Replies)
Discussion started by: perl_beginner
5 Replies

5. UNIX for Dummies Questions & Answers

Running different process from current process?

I have been having some trouble trying to get some code working, so I was wondering...what system calls are required to execute a different program from an already running process? (1 Reply)
Discussion started by: Midwest Product
1 Replies

6. UNIX for Dummies Questions & Answers

See if process is running and kill it

I need a simple line to run from apple remote desktop's Unix terminal on multiple different machines to see if Microsoft Entourage is running and kill it.. I imagine this could be done with a ps auxwww and grab the second field, (PID) put it into a variable and do a kill $variable using awk, but... (5 Replies)
Discussion started by: glev2005
5 Replies

7. UNIX for Dummies Questions & Answers

Current Process Running.

Hi all, When I issued command ps -ef|grep Vinay in a UNIX machine, I got the following Vinay 22491 1 255 Jun 18 ? 294248:53 -sh Vinay 26628 1 255 Jun 18 ? 294237:33 -sh Could you tell me what all process is running ? Please explain each of the fields. Thanks... (4 Replies)
Discussion started by: coolbhai
4 Replies

8. Shell Programming and Scripting

current running process in shell

hi what is the shell programming code to know the number of processes currently running on the machine & information about those processes. Another one is the configuration and usage of the UNIX file system? requesting all for help. thanks (1 Reply)
Discussion started by: moco
1 Replies

9. Programming

to find current running process

Hi All, The scenario is like this: There is a process say "A" which create a child process say "B" if some condition is true and process "A" terminates. "B" invokes some C program say "C" using 'execl' function. The job of program "C" is to keep polling the server until the server will be up.... (2 Replies)
Discussion started by: ranjkuma692
2 Replies

10. UNIX for Dummies Questions & Answers

how to kill process while keeping the submitted job running

:confused: I have a process which was schedule to run from 8am - 6pm daily. The scripts will search & run the commands that i was predefined in the database. Ususally, there were about 6-7 jobs for each submission and each job takes about 1-2 hrs and running one by one. And, I have a cron job... (3 Replies)
Discussion started by: hk_newbie
3 Replies
Login or Register to Ask a Question