I have a process currently occupying a terminal

]$ command some_argument

I want to exit from the terminal and go home, but in the mean time I don't want to kill this running process.

For the above running process, I want to achieve something like the following:

]$ nohup command some_argument >& logfile &
  • I started to flag this question as a dupe of this, but the other question doesn't cover the topic of redirecting STDOUT after a prior backgrounding. – Andrew B Aug 21 '13 at 21:44
  • How does disown keeps a log file that this process may produce to stdout ? Please remove the duplicate that you have flagged as disown alone doesn't answer this question. – iamauser Aug 21 '13 at 21:48
  • 1
    I updated my question a moment ago. The short version: not really feasible, unfortunately. :( (also, I had already retracted the dupeflagging+comment before your comment hit the website) – Andrew B Aug 21 '13 at 21:49

Disowning the process and redirecting STDOUT from an already backgrounded process isn't feasible for most users. This SO answer covers the topic pretty well.

Disassociating the process from the current shell isn't so hard: you're looking for disown. From the manpage:



       The shell exits by default upon receipt of a SIGHUP.   Before  exiting,
       an  interactive  shell  resends  the  SIGHUP  to  all  jobs, running or
       stopped.  Stopped jobs are sent SIGCONT to ensure that they receive the
       SIGHUP.   To  prevent the shell from sending the signal to a particular
       job, it should be removed from the jobs table with the  disown  builtin
       (see  SHELL  BUILTIN  COMMANDS  below)  or marked to not receive SIGHUP
       using disown -h.




       disown [-ar] [-h] [jobspec ...]
              Without options, each jobspec  is  removed  from  the  table  of
              active  jobs.   If jobspec is not present, and neither -a nor -r
              is supplied, the shell's notion of the current job is used.   If
              the -h option is given, each jobspec is not removed from the ta‐
              ble, 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 job‐
              spec does not specify a valid job.

If you want to learn more about what nohup and disown actually do, you can check out this question. (disclaimer: shameless self-promotion)


I understand you are currently using a Linux based OS but for the record and in case someone happening to use Solaris 10 or newer find this page while looking for a solution, Solaris nohup implements what you are looking for:

$ command some_argument
^Z[1] + Stopped (SIGTSTP)        command some_argument
$ bg
[1]     command some_argument&
$ jobs -l
[1] + 1061       Running                 command some_argument
$ nohup -p 1061
Sending output to nohup.out
$ exit

Looks like you are close:

 nohup sh custom-script.sh > custom-out.log &

From here

  • 1
    How this is going to convert my running process on the terminal into a nohup ? – iamauser Aug 21 '13 at 21:07
  • You have to start the process this way. If you are asking how to make a pre-existing process go to nohup you want to use "disown", not sure if you can get the stdout redirected then though – TheFiddlerWins Aug 22 '13 at 12:46
  • The question clearly asked about an already running process. – Jonathon Reinhart Dec 21 '16 at 21:22
  • I clearly didn't read it then. Try disown for already running processes – TheFiddlerWins Dec 28 '16 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.