run a command immune to hangups, with output to a non-tty
add an example, a script, a trick and tips
nohup ./run &
tail -f nohup.out
nohup ./testreadblock $1
How do I fork a process that doesn't die when shell exits?
You do not mention if this is running as an X app or a console
If it's as a console app, of course it needs to close. You got
rid of it's input/output, more technically the (pseudo) tty it
was on. It's very unlikely this is what you meant, so let's
assume you're talking about an X app.
nohup should work, not sure why it isn't. When the
shell closes, it sends
SIGHUP to all processes in
its process group. nohup tells the command to ignore SIGHUP.
You can also try setsid, which disconnects the process from the
alias emacs='setsid emacs'
Can I force nohup output to the screen instead of a file?
That would defeat the purpose of nohup, use
Is it possible to change a running process in linux, so that it doesn't quit upon logging out?
In Bash, you could
disown [-ar] [-h] [jobspec â€¦ ]
jobspec is removed from the table of active
-h SIGHUP is not sent to the job if the shell
receives a SIGHUP. current job .
-a all the
-r running jobs.
Shell stuff: job control and screen
If you use the bash shell, then you have an alternative (don't
you always?) Instead of using nohup, just run the command
normally, put it in the background one of the two ways we've
discussed, and then disown -h the job.
$ tar cjf /backup/rob/home.tar.bz2 . &
$ disown -h
You can then safely logout or close your terminal. As with
nohup, if you close the terminal or logout, you will not be
able to access that command directly using the jobs and
fg <N> commands..
Related posts on the Stack Exchange network:
Continue SSH background task/jobs when closing SSH
When you use
screen you need to detach with
CTRL+A+D before you exit
Alternatively, if you want to run a process directly with screen
you can use
screen -dmSL [session name] [commands]
-d starts a screen session and immediately
detaches from it
-m forces creating a new screen session
-S lets you give the session a name
-L turns on logging to
screen -dmSL workstuff myscript.sh
You can then either:
resume later using
check the log file
Correct Method of Utilizing nohup in Batch Process
nohup on each line is not the
answer.Â If you do that, and the session is
terminated, the currently-running program will run to completion,
but then the script will terminate without
nohupÂ filebuilder.sh will work, but then
you have to remember to do it every time.Â A couple
Â 1. Write
filebuilder.sh to say
exec nohup name_of_the_real_filebuilder.sh
Â 2. Put
trap "" 1
at the beginning of your script.Â (1Â is
the numeric value of the â€œhangupâ€
Nohup does not run process in background
nohup bash -c "while [ true ]; do echo test; done" &
Nohup provides you immunity to hangup signals. But it does not
automatically set the process to background.
It's the & at the end of the command that causes it to run in
How to resume simulations running in background
If jobs were interrupted due to insufficient disk space, they
most likely exited completely. This depends on the way they were
programmed, but I can't imagine any process waiting for user
input before exiting due to failed write operations or other
symptoms of a full disk.
There's no way to "resume" other than starting the processes
The only possibility you have is when the process (whatever it
is) is aware of what output it has already produced and where it
needs to start again. For example, the process could scan its
output for already existing items and then continue where it left
off. But no process does this by default, you need to explicitly
program it this way.
It all depends on what exactly this process is, what it takes as
input, and what output it produces (so, if we knew that, we could
probably help you better).
Using nohup in Ubuntu - how to make it not show the job number?
The  27918 is coming from the & not the nohup.
Put the command you want to run in the background inside a script
/path/to/command & >/dev/null 2>/dev/null
and then call that with nohup
nohup sh /path/to/my/script > foo.out 2> foo.err < /dev/null
The output of & is then redirected to /dev/null inside the
Background process (nohup &) suspends/resumes when user logs out/logs in
I usually redirect
well as using
nohup. I'm not sure if it is necessary
but it works for me.
If the program ever reads from
stdin it will wait.
can I `dtach` or `renice` graphical programs like `evince`?
dtach does not influence OS resources in the sense
that it reduces RAM or CPU cycles,
dtach detaches a
process from it's parent process.
renice on the
other hand increases / decreases the priority of the process for
the schedular; the process will gain more cpu-cycles .
So: yes, you can use
dtach to detach
evince from your
xterm (I doubt that
you open evince via
xterm anyway). This would only
ensure that closing
xterm won't close
evince. Yes, you can
renice a lower
evince and then the scheduler will call
evince less often. Memory wise there won't be any
change at all. To reduce work load you might minimize
evince so it is not visible and thus nothing
new will be rendered and no checks against
overlapping due to other programms will take place.
But, and I mean that in all seriousness: Stop fiddling around
with your system in such micromanagement style and just buy more
RAM. As long as you don't open 1000s of
evince to be
read later (which is a usage pattern I would change in the first
place) the OS will behave not really differently when you
microtune the OS. If you don't want to read the
.pdfs now: save them to disk. Problem solved.
How to find out is a program run with nohup or not?
You need to know pid of process you want to look at. You can
- 3730 Running sleep 1000 &
+ 3734 Running nohup sleep 1000 &
Actually, this might already tell you the answer, unless you
logged off and logged in again (then
will not show anything).
Take a look at
nohup will list
mvp@linux:~$ ls -l /proc/3734/fd
l-wx------ 1 mvp mvp 64 Oct 29 02:32 0 -> /dev/null
l-wx------ 1 mvp mvp 64 Oct 29 02:32 1 -> /home/mvp/nohup.out
l-wx------ 1 mvp mvp 64 Oct 29 02:32 2 -> /home/mvp/nohup.out
and started without
nohup will not:
mvp@linux:~$ ls -l /proc/3730/fd
lrwx------ 1 mvp mvp 64 Oct 29 02:28 0 -> /dev/pts/1
lrwx------ 1 mvp mvp 64 Oct 29 02:28 1 -> /dev/pts/1
lrwx------ 1 mvp mvp 64 Oct 29 02:28 2 -> /dev/pts/1
Ctrl+c in a sub process is killing a nohup'ed process earlier in the script
Have you tried disown?
disown -h %1
or whatever your job is; disown is a shell built-in, its
man page states:
disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of
active jobs. If the
-h' option is given, the job 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 jobspec is
not present, and neither the-a' nor
-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
Funny thing, your construction works on my Arch Linux:
$ cat testm
nohup /home/mario/temp/waste &
less +F out.log
$ cat waste
while [ 1 ]; do
find / -print 2>1 1> out.log
nohup: appending output to â€˜nohup.outâ€™
$ ps ax | grep waste
19090 pts/2 S 0:00 /bin/sh /home/mario/temp/waste
19124 pts/2 S+ 0:00 grep waste]
Before the ps command, I had to scroll the out.log file,
then Ctrl+C, then q.
ignoring hangup signals.
display this help and exit
output version information and
input is a terminal, redirect it from /dev/null. If standard
output is a terminal, append output to
’nohup.out’ if possible,
’$HOME/nohup.out’ otherwise. If standard error
is a terminal, redirect it to standard output. To save
output to FILE, use ’nohup COMMAND >
shell may have its own version of nohup, which usually
supersedes the version described here. Please refer to your
shell’s documentation for details about the options it
Copyright © 2012 Free Software Foundation, Inc. License
GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute
it. There is NO WARRANTY, to the extent permitted by law.
Report nohup bugs to bug-coreutils[:at:]gnu[:dot:]org
GNU coreutils home page:
General help using GNU software:
Report nohup translation bugs to
documentation for nohup is maintained as a Texinfo
manual. If the info and nohup programs are
properly installed at your site, the command
coreutils 'nohup invocation'
should give you
access to the complete manual.
Written by Jim