InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

Menu
  • Home
  • Sitemap

Python Programming Language Best Tutorials and Code Examples

Learn Python Right Now!
Home
Bash
Running Long Jobs Unattended in bash
Bash

Running Long Jobs Unattended in bash

InfinityCoder February 9, 2017

You ran a job in the background, then exited the shell and went for coffee. When you came back to check, the job was no longer running and it hadn’t completed.

In fact, your job hadn’t progressed very far at all. It seems to have quit as soon as you exited the shell.

If you want to run a job in the background and expect to exit the shell before the job completes, then you need to nohup the job:

1
2
3
$ nohup long &
nohup: appending output to `nohup.out'
$

When you put the job in the background (via the &), it is still a child process of the bash shell.

When you exit an instance of the shell, bash sends a hangup (hup) signal to all of its child processes.

That’s why your job didn’t run for very long. As soon as you exited bash, it killed your background job. (Hey, you were leaving; how was it supposed to know?)
The nohup command simply sets up the child process to ignore hang-up signals.

You can still kill a job with the kill command, because kill sends a SIGTERM signal not a SIGHUP signal. But with nohup, bash won’t inadvertently kill your job when you exit.
The message that nohup gives about appending your output is just nohup trying to be helpful.

Since you are likely to exit the shell after issuing a nohup command, your output destination will likely go away—i.e., the bash session in your terminal window would no longer be active.

So, where would the job be able to write? More importantly, writing to a non-existent destination would cause a failure.

So nohup redirects the output for you, appending it (not overwriting, but adding at the end) to a file named nohup.out in the current directory.

You can explicitly redirect the output elsewhere on the command line and nohup is smart enough to detect that this
has happened and doesn’t use nohup.out for your output.

Share
Tweet
Email
Prev Article
Next Article

Related Articles

Testing for Equal in bash
You want to check to see if two shell variables …

Testing for Equal in bash

Keeping Files Safe from Accidental Overwriting in bash
You don’t want to delete the contents of a file …

Keeping Files Safe from Accidental Overwriting in bash

About The Author

InfinityCoder
InfinityCoder

Leave a Reply

Cancel reply

Recent Tutorials InfinityQuest

  • Adding New Features to bash Using Loadable Built-ins in bash
    Adding New Features to bash Using Loadable …
    June 27, 2017 0
  • Getting to the Bottom of Things in bash
    Getting to the Bottom of Things in …
    June 27, 2017 0

Recent Comments

  • fer on Turning a Dictionary into XML in Python
  • mahesh on Turning a Dictionary into XML in Python

Categories

  • Bash
  • PHP
  • Python
  • Uncategorized

InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more

About Us

Start learning your desired programming language with InfinityQuest.com.

On our website you can access any tutorial that you want with video and code examples.

We are very happy and honored that InfinityQuest.com has been listed as a recommended learning website for students.

Popular Tags

binary data python CIDR convert string into datetime python create xml from dict python dictionary into xml python how to create xml with dict in Python how to write binary data in Python IP Address read binary data python tutorial string as date object python string to datetime python

Archives

  • June 2017
  • April 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
Copyright © 2021 InfinityQuest - Programming Code Tutorials and Examples with Python, C++, Java, PHP, C#, JavaScript, Swift and more
Programming Tutorials | Sitemap