Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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?

  2. #2
    hi,

    the jobs builtin returns information about process in background.
    if your script is the second on the list printed, then
    Code:
    kill %2

  3. #3
    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.

  4. $spacer_open
    $spacer_close
  5. #4
    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.

  6. #5
    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?

  7. #6
    yes,
    Code:
    echo $$ > pid_file
    and no, background processes keep their PID.
    when the terminal is closed, then they're attached to init, and get PPID 1

  8. #7
    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.

  9. #8
    why not?
    you kill processes by their PID ! (their Parent's PID is useless)
    ?

  10. #9
    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. #10
    what does print
    Code:
    ps -C yourScriptName -o pid,ppid

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •