Monday, April 25, 2011

How do I put an already running process under nohup

I have a process that is already running for a long time and don't want to end it.

How do I put it under nohup (i.e. how do I cause it to continue running even if I close the terminal?)

From stackoverflow
  • The command to seperate a running job from the shell ( = makes it nohup) is disown and a basic shell-command.

    From bash-manpage (man bash):

    disown [-ar] [-h] [jobspec ...]

    Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.

    That means, that a simple

    disown
    

    will remove all jobs from the job-table and makes them nohup

  • Using the Job Control of bash to send the process into the background:

    > [crtl]+z
    > bg
    

    And as Sam mentioned you have to execute disown to avoid killing the process after you close the terminal.

    disown
    
    flybywire : works as advertised, thank you!
  • these are good answers above, I just wanted to add a clarification, You can't disown a pid or process, you disown a Job, and there is an important distinction. A Job is something that is a notion of a process that is attached to a shell. Therefore, you have to through the job into the background (not suspend it) and then disown it.

    issue: % jobs

    [1] running java

    [2] suspended vi

    % disown %1

    See http://www.quantprinciple.com/invest/index.php/docs/tipsandtricks/unix/jobcontrol/ for a more detailed discussion of Unix Job Control.

  • Good tip it helped me a lot. Keep Rocking!!!

0 comments:

Post a Comment