Operations 3 min read

Can nohup Keep Your Linux Processes Running After Logout? A Practical Demo

This article explains how the Linux nohup command lets a process continue running after the terminal is closed, demonstrates it with an infinite-loop PHP script, and clarifies why the jobs command cannot list background tasks across different sessions.

Architecture Talk
Architecture Talk
Architecture Talk
Can nohup Keep Your Linux Processes Running After Logout? A Practical Demo

Before diving into the main topic, let's briefly learn the Linux nohup command.

The nohup command is used when you want a process to continue running after you log out or close the terminal. It prevents the process from receiving a SIGHUP signal. A typical use case is keeping a message‑queue consumer alive.

Example command (shown in the image):

We open a shell and run a demo.php script that loops infinitely, printing a variable. The script is intended to verify whether nohup can run a process in the background. If it works, the numbers in nohup.out should keep increasing.

After starting the script with nohup php demo.php &, we observed that nohup.out indeed grew and the jobs command listed the background task. However, when we opened a new terminal window (a new session) and ran jobs, the task was not listed.

Investigation showed that the process was still running (checked with ps aux | grep demo.php) and nohup.out continued to receive output, indicating that the process survived the terminal closure.

The jobs command cannot display jobs across different sessions.

The nohup command can keep a script running in the background regardless of whether the user logs out.

Process ManagementLinuxshell scriptingbackground jobsystem operationsnohup
Architecture Talk
Written by

Architecture Talk

Rooted in the "Dao" of architecture, we provide pragmatic, implementation‑focused architecture content.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.