kill with nohup
I would like use kill with nohup function , I think it should use "kill -TERM" but if I want to also use kill level , for example "kill -8" , can advise how can I combine these function ? I tried "kill -TERM -8" is not work .
|
Have a look at the man page for kill. Basically the syntax is kill -s 15 pid or kill -s SIGTERM pid. For a list of signals run kill -l
|
The numbers and the names are alternatives. For example, these two commands do exactly the same thing:
Code:
kill -9 12345 |
Quote:
SIGHUP signal mean kill signal ? if yes , is it "kill -s SIGTERM" ? thx |
SIGHUP is the "hang-up" signal which is sent to children of login shells when the shell terminates. Think of the old set-up where a user logs into an old physical terminal like a vt100... each user is connected to the computer via a serial port. If the terminal device is turned off, or disconnects, the user is considered to be "hanging up" the serial line. That's the origin of the name anyhow.
Most programs will terminate if they receive SIGHUP (it is the default behaviour if the program does not explicitly handle the signal). By running with nohup, the nohup program traps the signal and ignores it, thus preventing the program from terminating. SIGTERM (terminate) is an instruction to terminate a process. Think of it like a polite request for a program to close now. This gives the program a chance to terminate cleanly (e.g. if it's half way through some operation which it might want to finish first). SIGINT (interrupt) is sent to a process when the user presses control-c (and the process is in the foreground in a terminal). Most applications close then they receive this signal. The default behaviour for all these signals happens to be to terminate the program, but the program may choose to ignore the signal, or even trigger some other action instead of termination. SIGKILL is a special in that a program cannot trap the signal - the process cannot avoid termination if it is sent SIGKILL - the OS just kills it immediately. You may have noticed when you shut down in some distros you see a message something like "Shutting down... Sending TERM to all processes", then a short delay while the OS waits for all the processes to finish cleanly. There is then usually another message saying, "Sending KILL to all processes". This is the OS who, having waited patiently for programs to close doesn't ask nicely again - it just kills any remaining programs. |
Still No Luck
Hi. This the most comprehensive and clear discussion I have found on this issue. Thank you for sharing.
I have submitted a simple shell script with nohup and cannot kill the process. It simply spawns new processes. I am using: $> kill -[switch] [process id] which will terminate the process and create a new process. I have tried to send the following switches in order as suggested on another help site (http://stackoverflow.com/questions/8...-nohup-process) SIGTERM (15) SIGINT (2) SIGKILL (9) Any insights or suggestions would be greatly appreciated. |
kill will never create new processes. probably you need to kill the parent process but I'm not really sure. nohup cannot protect any process against kill -9. processes can catch and tries to handle (ignore) some signals, like 1, 2 or 15, but not all of them.
|
Post your script please
|
Script as Requested
It is a simple script...
$> nohup my-script.sh & # Convert m4a to mp3 for i in *.m4a; do \ ffmpeg -i "$i" -acodec libmp3lame -ac 2 -ab 192k "${i%m4a}mp3"; \ done Thank you in advance for any insights. |
OK; some notes
1. This Code:
nohup my-script.sh & Normally you wouldn't have this; instead you'd use a path eg Code:
nohup ./my-script.sh & Try Code:
# Convert m4a to mp3 Normally Code:
kill pid As he said, use 'kill -l' (lowercase L) to see all signals Do NOT use -9 = SIGKILL if you can avoid it, as it kills the process without allowing it to clean up, which can lead to corrupt files. |
chrism01,
Thank you for taking the time to analyze and educate so clearly. Greatly appreciated. ~bobsmith5002 |
Are you sure you're picking the right pid? My experience with nohup is limited, and i am not sure how it works, but you should be able to capture the pod with $! so you can later kill it
Code:
nohup <...> |
Actually, $! is set by backgrounding (using the '&' cmd/char), although I probably always use '&' if I'm going to use nohup ...
|
All,
It is what chrism01 suggested. I foolishly did not detect the proper process id in grep. This allowed the true parent process id to continue re-spawning new 'ffmpeg' children. TLDR - I am in the learning curve with 'nohup' - painfully so. Many thanks, bobsmith5002 |
All times are GMT -5. The time now is 08:00 PM. |