Results 1 to 10 of 18
Hello,
when I call a script by using "nohup script &", it runs in the background. However, this script is still a child process of another process, the shell. Right?
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-08-2012 #1Just Joined!
- Join Date
- Oct 2012
- Posts
- 29
Question about child processes
Hello,
when I call a script by using "nohup script &", it runs in the background. However, this script is still a child process of another process, the shell. Right?
Imagine I have multiple background shell scripts running, but I want to send a kill signal to a specific background script. Is that possible? If so, how could it work?
- 11-08-2012 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
hi,
the jobs builtin returns information about process in background.
if your script is the second on the list printed, thenCode:kill %2
- 11-08-2012 #3Just Joined!
- Join Date
- Oct 2012
- Posts
- 29
That's not robust enough, because it won't survice any restarts, PID is also volatile. I am looking for a mechanism that allows me to kill a background script like a normal process.
- 11-08-2012 #4Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
then create your own scriptname.run.pid file, which will contain only the pid of the script, at the start of the script so you'll be able to get its pid by searching scriptname.run.pid, and printing its content.
initscripts do this.
- 11-08-2012 #5Just Joined!
- Join Date
- Oct 2012
- Posts
- 29
Thanks. You mean something like $$ > pid_file?
So a background process has an individual ID, but the PPID of every background prozess is 1 (the init process), because the former parent process has already been terminated?
- 11-08-2012 #6Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
yes,
and no, background processes keep their PID.Code:echo $$ > pid_file
when the terminal is closed, then they're attached to init, and get PPID 1
- 11-08-2012 #7Just Joined!
- Join Date
- Oct 2012
- Posts
- 29
And that's where the problem lies. When I start a nohup process and write his pid into a file, then I can't use this file afterwards to kill the nohup process.
- 11-08-2012 #8Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
why not?
you kill processes by their PID ! (their Parent's PID is useless)
?
- 11-08-2012 #9Just Joined!
- Join Date
- Oct 2012
- Posts
- 29
When I save the pid in a file and then call kill with the saved pid value as parameter, I get this message:
Code:bash: kill: (11447) - No such process
- 11-08-2012 #10Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
what does print
Code:ps -C yourScriptName -o pid,ppid


8Likes
Reply With Quote
