nohup Command: Usage, nohup.out, and Keeping Jobs Running After the Terminal Closes

Test environmentRHEL familyAlmaLinux 9.8coreutils 8.32root accountDebian 12 · coreutils 9.1 regular accountChecked 2026-11-05
Process · job scheduling commandsnohupLocation/usr/bin/nohup
Keeps running after the terminal closes

To keep a job running after you close the terminal or lose your SSH connection, start it with the nohup command. nohup runs the command with the hangup signal (SIGHUP), which arrives when a terminal closes, set to be ignored. When a sleep started with nohup and a sleep started without it were run together on an AlmaLinux 9 server and the terminal was closed, only the one started with nohup was left running.

The output below comes from an AlmaLinux 9.8 server (root account) and a Debian 12 server (regular account). A sleep stood in for a long-running job, and only the PID received at launch was given when stopping it. Times are printed in UTC.

1️⃣ How to use the nohup command

  • ↪️ The trailing & and what happens when you close the terminal

Put nohup in front of the command to run, and use the & at the end of the command for background execution. According to the official GNU manual, nohup itself does not send the command to the background, so without the & the prompt does not come back until the command finishes.

nohup sleep 300 &
[1] 3431609
nohup: ignoring input and appending output to 'nohup.out'

[1] is the job number and 3431609 is the PID of the started process. The message that followed says the process does not read keyboard input and appends its output to the file nohup.out.

The PID of the job you just started is kept in $!, so run [echo $!] right after starting it and note the number down; use that same number when you check its status or stop it.

echo $!
3431609

When a terminal closes, the shell receives the hangup signal and sends the same signal to the jobs it started (per the official Bash manual). To check this, [nohup sleep 300 &] and, without nohup, [sleep 301 &] were started together in a new terminal.

sleep 301 &
[2] 3432892
jobs -l
[1]- 3432883 Running                 nohup sleep 300 &
[2]+ 3432892 Running                 sleep 301 &

With both jobs Running, the terminal window was closed and the two PIDs were checked with ps from another shell.

ps -p 3432883,3432892 -o pid,stat,etime,cmd
    PID STAT     ELAPSED CMD
3432883 S          00:05 sleep 300

Only sleep 300, started with nohup, was left; sleep 301, started without nohup, ended when the terminal closed.

A process started with nohup is like a phone in Do Not Disturb mode.

nohup is a command from the coreutils package. Check the installed version with the first line of --version. The AlmaLinux 9.8 server had 8.32 and the Debian 12 server had 9.1.

nohup --version | head -1
nohup (GNU coreutils) 8.32
nohup --version | head -1
nohup (GNU coreutils) 9.1

2️⃣ nohup.out and output redirection

  • ↪️ Setting a log file and /dev/null

If you do not choose where the output goes, nohup appends the command's output to nohup.out in the current folder. The newly created nohup.out was 0 bytes, and its permissions were -rw-------, readable and writable only by the user who created it.

ls -l nohup.out
-rw------- 1 root root 0 Oct 28 23:04 nohup.out

The official GNU manual says nohup creates nohup.out so that only the user who created it can read and write it, regardless of the umask setting. If it cannot write to the current folder, it writes to $HOME/nohup.out in the home folder, and if it cannot write there either, it does not run the command.

When a command that produces output was run with nohup, the output stayed in nohup.out after the command finished.

nohup sh -c 'echo start; sleep 2; echo end' &
[1] 3431985
nohup: ignoring input and appending output to 'nohup.out'
cat nohup.out
start
end
[1]+  Done                    nohup sh -c 'echo start; sleep 2; echo end'

Done on the last line is the shell's notice that the job has finished. nohup.out is not recreated on each run but appended to at the end of the same file, so if you start several jobs from the same folder, their output gets mixed in one file.

To keep a separate log for each job, set the output file with > and send error output to the same file with 2>&1.

nohup sh -c 'echo start; sleep 300' > job.log 2>&1 &
[1] 3432059
cat job.log
nohup: ignoring input
start

With 2>&1 added, the terminal showed only the job number and PID, and nohup's notice [nohup: ignoring input] was written to the first line of the log file.

If you add only > and leave out 2>&1, the terminal shows a notice that error output is being sent to the standard output file.

nohup sleep 300 > job2.log &
[2] 3432097
nohup: ignoring input and redirecting stderr to stdout

Send the output of jobs you do not need to keep to /dev/null. Here too, the terminal showed only the job number and PID.

nohup sleep 300 > /dev/null 2>&1 &
[3] 3432137

The table below shows where the output went and what appeared in the terminal for each of the four ways of running it.

How it is runWhere output goesMessage in the terminal
nohup command &nohup.out in the current foldernohup: ignoring input and appending output to 'nohup.out'
nohup command > file &The given file (error output included)nohup: ignoring input and redirecting stderr to stdout
nohup command > file 2>&1 &The given fileNone (the notice goes to the first line of the file)
nohup command > /dev/null 2>&1 &DiscardedNone

3️⃣ Checking and stopping nohup processes

  • ↪️ jobs, ps, kill

The jobs list shows only jobs started from the current shell, so after you close the terminal and log in again, check a nohup process with ps -p and its PID. While you are still in the same shell, jobs -l shows the job number, PID and state together.

jobs -l
[1]+ 3431609 Running                 nohup sleep 300 &

Put a PID after ps -p and pick columns with -o, and only that process's line is shown. S in STAT means it is sleeping while it waits for an event, and ELAPSED is the time since it started.

ps -p 3431609 -o pid,stat,etime,cmd
    PID STAT     ELAPSED CMD
3431609 S          00:03 sleep 300

To stop it, use kill followed by the PID.

kill 3431609

kill printed nothing, and when jobs was run next, the job appeared as Terminated and then dropped out of the list.

jobs
[1]+  Terminated              nohup sleep 300

Running ps again with the same PID printed only the header, which confirmed that the process had ended.

ps -p 3431609 -o pid,stat,etime,cmd
    PID STAT     ELAPSED CMD

nohup ignores only the hangup signal, so sending that same signal directly with [kill -HUP] does not end the process. kill -HUP was sent to sleep 305, started with nohup, and to sleep 306, started without it.

kill -HUP 3437119 3437128

A check with jobs -l then showed only the nohup one still Running, while sleep 306 ended with Hangup.

jobs -l
[1]- 3437119 Running                 nohup sleep 305 &
[2]+ 3437128 Hangup                  sleep 306

If you give kill no signal, it sends SIGTERM, so a job started with nohup also ends with [kill PID].

4️⃣ nohup command vs. disown, and options

  • ↪️ disown -h, when to choose tmux, and an options summary

🔲 nohup vs. disown

disown is a bash builtin for jobs that are already running: it detaches a job started with & but without nohup from the terminal's hangup signal later on. disown does not send output to nohup.out, so for a job that produces output, set where the output goes with > file when you start it.

According to the official Bash manual, disown without options removes the job from the jobs list, while disown -h keeps it in the list and only stops the hangup signal from reaching it. First, sleep 302 was started and then disown was run.

sleep 302 &
[1] 3433230
disown

disown printed nothing, and jobs -l run right after it also returned nothing.

jobs -l

Next, sleep 303 was started and disown -h was run on job number %1.

sleep 303 &
[1] 3433343
disown -h %1

A check with jobs -l showed the job still in the list.

jobs -l
[1]+ 3433343 Running                 sleep 303 &

One more sleep, sleep 304, was started with no handling at all, the terminal was closed, and the three PIDs were checked from another shell.

sleep 304 &
[2] 3433474
ps -p 3433230,3433343,3433474 -o pid,stat,etime,cmd
    PID STAT     ELAPSED CMD
3433230 S          00:11 sleep 302
3433343 S          00:08 sleep 303

The two jobs given disown and disown -h were left, and only sleep 304, which had no handling, ended. The four methods compare as follows.

MethodWhen to usejobs listAfter the terminal closesOutput
nohup command &At launchRemainsRemainsnohup.out or the given file
command & then disownAfter launchSkippedRemainsUnchanged
command & then disown -hAfter launchRemainsRemainsUnchanged
command & only—RemainsEndedUnchanged

For work where you need to bring the session screen back and keep typing, a terminal multiplexer such as tmux is the right fit; for work you start once and only collect the result from a file, nohup is enough.

🔲 nohup command options

📌 Main options: results from this article

OptionTaskResult in this article
--versionPrints version information and exitsAlmaLinux 9.8 server: nohup (GNU coreutils) 8.32, Debian 12 server: nohup (GNU coreutils) 9.1

📎 Other options: per the official manual

OptionTask
--helpPrints help and exits

🔲 nohup command simulator

In the simulator below, start a job with nohup, close the terminal and reconnect with the 🔌 chip, and see for yourself which processes are left.

nohup command simulatorcoreutils 8.32
[root@server work]#
It runs only inside your browser and does not start real processes. sleep times follow the real clock, and ↑↓ bring back commands you typed earlier.

🔢 FAQ & Recommended Content

According to the official GNU manual, nohup exits with 125 if nohup itself fails, 126 if the command was found but could not be run, and 127 if the command was not found. On an AlmaLinux 9 server, entering nohup alone without a command gave 125, ./job.sh without execute permission gave 126, and the nonexistent command nosuchcmd gave 127.

nohup does not change the nice value, so use nice together with it, as in [nohup nice -n 10 sleep 307 &]. A ps check of the sleep started this way showed 10 in the NI column and SN in STAT, with the N that marks low priority.

The nohup command has only two options, [--help] and [--version]. According to the official GNU manual, options go before the command to run.

ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove your humanity: 4   +   4   =