If I have a large shell script running as root, say for example like one that copies a ton of files, how would I kill the shell script and any processes that it created?
Please post the script making it clear what Operating System and shell is in use.
In general your scripts need to trap a "kill -15" (hangup) and exit cleanly.
There is rarely any reason to issue a "kill -9".
It would help to know the Operating System so we can determine the best way to find the parent and child of the runaway process. This would determine the syntax of the "ps" comand with view to finding out the process tree and thence the process we need to kill.
I'm running Mac OS X, Darwin/BSD shell. I've written a native Mac OS X Cocoa application that launches a shell script. I need some sort of command that would be able to immediately kill the shell script and any other processes that it spawned.
I'm not sure if it's available in OS X, but the "kill" utility - not the shell built-in command - has the ability to kill entire process groups:
That example would send the SIGTERM signal to all processes in the process group that process 1234 is in. The double-dash argument is necessary to indicate that the end of options has been reached and allow the PID argument to be interpreted as a negative PID instead of an erroneous numeric option.
Note that the shell built-in kill command in my experience does not have this capability, so you can't just type "kill ...." and get this effect - that will invoke the shell's built-in command.
The problem with using the kill utility in this manner is that a shell script is usually part of the same process group as the login shell that started it. So if you kill the shell script this way, you'll kill your login script, too.
Generally, the "setsid()" call is used in compiled programs to create a new process group. I'm not aware of any ways to do that in a shell script, but there may be. I'm certainly no expert on OS X particulars.
I followed the directions here
Free Twitter Source Code ? Twitter Database Server: Install
and created a php script that enters twitter keyword searches into a MySQL DB.
When you execute the files outlined in the above link, a script starts indefinitely.
I've noticed that the scripts... (6 Replies)
I was just playing with the processes and suddenly a question striked my mind:
What will happen if we kill directly the shell process?? :rolleyes:
Do anyone know?
Will the system shutdown?
Or the system wont let it be killed? (5 Replies)
Hello all,
I need to write a shell script that does the following; Allows you to kill a job,(1) listing only the jobs you own, (2) asks for which job to kill, (3) kills the job and (4) confirms kill...
I am not sure if I need to first run the job command and pipe it with kill? Which options... (6 Replies)
Hello All,
i hope you are fine.
I need a little help from you people--
inside a script i want to kill a parent process by checking it with the child process..
p_pid=`ps -e | awk '/ra_cmd_d/ {print$1}'`
here i am selecting the child process id in p_pid.
next--
sleep_pid=`ps -af |... (3 Replies)
Hi,
I am trying to automate the killing of named processes of which I found a good solution here on the forums but as I am pretty much a begginer to linux I am having an issue. The code I found is:
kill $(ps -ef | nawk '/monitoreo start/ { print $2}'}
but what I want to do is replace... (3 Replies)
I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time.
Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
i am using script to connect remotly to server and run some commands , one of these commands is to kill some process but tried different ways with no hope
sshpass -p 'pass' ssh -o StrictHostKeyChecking=no server kill -9 `pgrep procs`
getting error message "kill: bad argument count"
... (2 Replies)
Hey all. I'm brand new to this forum and am looking for some help. I have a script that verifies that the backup tapes are working correctly. Basically is uses 1 command: restore -xpqvf > rootvglog
I use this for each volume group that we have. We run this everyday but the problem is, we... (4 Replies)
Hi All,
I have a written a script in korn shell for importing data into a oracle database. The shell invokes the import within the script. I want to kill this import (child process) . I tries using trap, but this does not kill the import even if i press cnt c. i have to login into other terminal... (2 Replies)
can I do
ps -ef | grep <process_name>
and kill the process is it exists?
and send a mail to me that the process was found and killed
Thanks much...
KS (4 Replies)