UNIX Tutorials, Tips, Tricks and Shell Scripts

UNIX Nohup Command: How to Keep Commands or Shell Scripts Running After You Log Out


When working with the UNIX operating system, there will be times when you will want to run commands that are immune to log outs or unplanned login session terminations. This is especially true for UNIX system administrators. The UNIX command for handling this job is the nohup (no hangup) command.

Normally when you log out, or your session terminates unexpectedly, the system will kill all processes you have started. Starting a command with nohup counters this by arranging for all stopped, running, and background jobs to ignore the SIGHUP signal.

The syntax for nohup is:

nohup command [arguments]

You may optionally add an ampersand to the end of the command line to run the job in the background:

nohup command [arguments] &

If you do not redirect output from a process kicked off with nohup, both standard output (stdout) and standard error (stderr) are sent to a file named nohup.out. This file will be created in $HOME (your home directory) if it cannot be created in the working directory. Real-time monitoring of what is being written to nohup.out can be accomplished with the "tail -f nohup.out" command.

Need a simple script to monitor and restart your system processes automatically?

See ProcMonUX - a Simple Lightweight Process Monitor Script with Alerts, Restart and Logging for more info. It works with both UNIX and Linux...and it's FREE!

Although the nohup command is extremely valuable to UNIX system administrators, it is also a must-know tool for others who run lengthy or critical processes on UNIX systems.

Do you need to learn UNIX or Linux, including how to read and write shell scripts? If you are ready to move past the basics, either of these online courses is a good place to start...

UNIX and Linux Operating System Fundamentals contains a very good "Introduction to UNIX Shell Scripting" module, and should be taken if you are new to the UNIX and Linux operating system environments or need a refresher on key concepts.

UNIX Shell Scripting is a good option if you are already comfortable with UNIX or Linux and just need to sharpen your knowledge about shell scripting and the UNIX shell in general.

Both courses include access to an Internet Lab system for completing the course's hands-on exercises, which are used to re-enforce the key concepts presented in the course. Any questions you may have while taking the course are answered by an experienced UNIX technologist.

Thanks for reading, and have a great day!!!

Has this article been helpful to you? Would it benefit others? If you answered "yes" to either question, kindly share the page.

MORE READERS = MORE FUTURE ARTICLES
Thank you for sharing!