How to kill a script and all its subprocesses?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to kill a script and all its subprocesses?
# 1  
Old 10-05-2014
How to kill a script and all its subprocesses?

I'd like to terminate scripts.

These scripts are not by me, but other persons. These contain other programs such as ping, nmap, arp, etc.

If such a script is running, how can I terminate this script AND all processes called by this script?

These scripts are big so terminating all programs (pkill ping, pkill nmap etc.) is not an option.

Is there anything like "pkill script.sh" killing the script and all processes?

I startet a simple script "test.sh" containing nothing but a "ping www.google.com".
Using "ps ax | grep test.sh" returned nothing, so there is no test.sh in the process list. There is a ping process, but as written before, killing this is not an option.
# 2  
Old 10-05-2014
Welcome to UNIX.com

When you post a question it helps us to know what OS you are using. Otherwise we have to guess. Why this is important: some OS have a command like ptree that will display the pid of child processes.

As a guess, let's start here: experiment with the output of this (Linux):
Code:
ps axf -o pid,command
# or 
ps axf

Tweak the above until you get something that gives you what you want,
once you find a command that does what you want you can write a loop:
kill $([command that works for you here] | tr -s '\n' ' ')
# 3  
Old 10-06-2014
Or simply
Code:
kill $(command)

# 4  
Old 10-08-2014
Thanks for the answers Smilie
Unfortunately I am not wiser Smilie

OS is debian.
ps axf shows all processes, but not the script.
As stated above, I cannot terminate the processes, as I have to assume I do not know them.
I'd like to do a "pkill script.sh" which terminates the script and all its subprocesses.
# 5  
Old 10-08-2014
Maybe,

Code:
pkill -TERM -P $(pgrep script.sh)

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shells, forks, subprocesses... oh my

all, i've been reading to try and get an abstract idea of the process effeciency of commands , sed, bash, perl, awk, find, grep, etc which processes will spawn?, fork?, launch subshell?, etc and under what conditions? how do you know which commands have the faster and better stdio... (2 Replies)
Discussion started by: f77hack
2 Replies

2. Shell Programming and Scripting

Kill an specific process ID using the KILL and GREP commands

Good afternoon I need to KILL a process in a single command sentence, for example: kill -9 `ps -aef | grep 'CAL255.4ge' | grep -v grep | awk '{print $2}'` That sentence Kills the process ID corresponding to the program CAL255.4ge. However it is possible that the same program... (6 Replies)
Discussion started by: enriquegm82
6 Replies

3. Shell Programming and Scripting

kill the script

Hi ,I need your help to kill the script itself if run for more than 10 mins . main.sh nohup ./a1.sh param1 & nohup ./a2.sh param1 & wait #Wait for 2 scripts to complete and and kill the process if run more than 10 mins --- Thanks inadvace MR Please view this code tag... (2 Replies)
Discussion started by: mohan705
2 Replies

4. UNIX for Dummies Questions & Answers

kill script using alias name

Hi, I am using the below command to kill the firefox process i have opened in Redhat 5. ps -ef|grep fire|grep -v grep|awk '{print $2}'|xargs kill -9 If i execute the above command in terminal it works good and kills session. but when i use alias for that it is not working. alias... (2 Replies)
Discussion started by: nokiak810
2 Replies

5. Shell Programming and Scripting

Script to Kill a Process by Name...

Hello all... new to these forums and a bit of a newbie with linux aswell. I need to figure out how to write a shell script to kill a process by name as given to the script as an argument. I've got that part working OK, but i need to make sure that the script does not allow processes that are... (6 Replies)
Discussion started by: cannon1707
6 Replies

6. UNIX for Dummies Questions & Answers

What is meant by subprocesses?

I'm going through my UNIX book and came across a section on Customization and Subprocesses. Can someone tell me what a subprocess is -- for example, when the book says "Which shell 'thing' are known to subprocesses" what exactly does it mean? The book just talks about it without defining it... (10 Replies)
Discussion started by: Straitsfan
10 Replies

7. UNIX for Advanced & Expert Users

When kill doesnt work, how to kill a process ?

Hi All, I am unable to kill a process using kill command. I am using HP-UX system. I have tried with kill -9 and i have root privilages. How can i terminate this daemon ? ? ? Regards, Vijay Hegde (3 Replies)
Discussion started by: VijayHegde
3 Replies

8. Shell Programming and Scripting

Script to kill process

Hello guys, I have a process named monitoreo, with 'monitoreo start' my process start until i kill them, now i want to do 'monitoreo stop' to kill them. After 'monitoreo start' i have this process running: ps -af UID PID PPID C STIME TTY TIME CMD ati 10958 1495 ... (5 Replies)
Discussion started by: Lestat
5 Replies

9. Shell Programming and Scripting

kill script

Hi all! I wirte a little Shell Script, that kill pids by programm names. For example, when i want to kill any pid of xmms i use this command: kill -9 `ps -A | awk ' ($4=="xmms") {print $1}'` To put this in a "killprg" script i use the following linkes: #!/bin/bash echo "" echo "Programm... (2 Replies)
Discussion started by: donald1111
2 Replies

10. UNIX for Advanced & Expert Users

possibility to call subprocesses from ksh ??

Hi!! Is there a possibility to call/start a subproces using ksh ?? Hope that there is somebody to help me. thanks in advance. Corine (3 Replies)
Discussion started by: TheBlueLady
3 Replies
Login or Register to Ask a Question