Skip to main content

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?)


Source: Tips4allCCNA FINAL EXAM

Comments

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

    > [crtl]+z
    > bg


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

    disown -h

    ReplyDelete
  2. 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

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

    ReplyDelete
  4. Suppose for some reason Ctrl+Z is also not working, go to another terminal, find the process id (using ps) and run

    kill -20 PID
    kill -18 PID


    kill -20 will suspend the process and kill -18 will resume the process, in your other terminal

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.