LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-28-2007, 09:52 PM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
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 .
 
Old 11-28-2007, 10:20 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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
 
Old 11-29-2007, 12:56 AM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
The numbers and the names are alternatives. For example, these two commands do exactly the same thing:
Code:
kill -9 12345
kill -KILL 12345
nohup prevents a process receiving SIGHUP signal when the parent shell is closed (and sends SIGHUP to all child processes).
 
Old 11-29-2007, 01:04 AM   #4
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by matthewg42 View Post
The numbers and the names are alternatives. For example, these two commands do exactly the same thing:
Code:
kill -9 12345
kill -KILL 12345
nohup prevents a process receiving SIGHUP signal when the parent shell is closed (and sends SIGHUP to all child processes).
thx reply ,

SIGHUP signal mean kill signal ?
if yes , is it "kill -s SIGTERM" ?

thx
 
Old 11-29-2007, 01:34 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
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.
 
1 members found this post helpful.
Old 05-20-2012, 07:02 AM   #6
bobsmith5002
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
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.
 
Old 05-20-2012, 09:13 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,901

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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.

Last edited by pan64; 05-21-2012 at 12:51 AM. Reason: typo
 
Old 05-20-2012, 11:56 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Post your script please
 
Old 05-22-2012, 07:41 AM   #9
bobsmith5002
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
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.

Last edited by bobsmith5002; 05-22-2012 at 07:43 AM. Reason: included nohup command
 
Old 05-22-2012, 07:01 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
OK; some notes

1. This
Code:
nohup my-script.sh &
implies you have the current dir '.' defined in your $PATH. This is generally considered a security risk, as someone could put a copy of an important prog eg rm into your current dir and it may take effect before the real one in eg /bin.
Normally you wouldn't have this; instead you'd use a path eg
Code:
nohup ./my-script.sh &
2. Your actual code looks odd; the '\'s are redundant. They are only used when you want to create a very long cmd line (eg 132 chars) and need to fold it eg so it can be seen in 80 chars.
Try
Code:
# Convert m4a to mp3
for i in *.m4a
do
    ffmpeg -i "$i" -acodec libmp3lame -ac 2 -ab 192k "${i%m4a}mp3"
done
Your inability to stop this implies to me that you are actually trying to kill the ffmpeg process(es), not the pid of the script itself.

Normally
Code:
kill pid
is sufficient and sends the SIGTERM signal by default; see matthewg42's explanation above.
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.

Last edited by chrism01; 05-23-2012 at 08:23 PM.
 
1 members found this post helpful.
Old 05-23-2012, 07:24 AM   #11
bobsmith5002
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
chrism01,

Thank you for taking the time to analyze and educate so clearly. Greatly appreciated.

~bobsmith5002
 
Old 05-24-2012, 04:37 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
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 <...>
pid=$!
...
.
.
kill -9$pid
But this really depends on what exactly your script is doing.
 
Old 05-24-2012, 08:39 PM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, $! is set by backgrounding (using the '&' cmd/char), although I probably always use '&' if I'm going to use nohup ...
 
Old 05-25-2012, 07:14 AM   #14
bobsmith5002
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
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
 
  


Reply

Tags
kill, nohup, signal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
To use or not to use nohup entz Linux - Server 9 04-07-2007 04:52 PM
Need to install nohup osmania Linux - Software 5 02-01-2007 03:20 PM
a way to ALWAYS get nohup behavior? Krelian Linux - General 9 12-18-2006 06:08 PM
problem with nohup command and nohup file size vbseeker Linux - General 1 09-17-2006 11:36 AM
help on nohup vinayuh Linux - General 3 07-22-2005 12:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration