A nohup process continues running even after you log out, but you need the right command to find it in the system’s process list. Understanding how to check nohup process in linux is essential for system administrators and developers who rely on background tasks. This guide walks you through every method, from basic commands to advanced filtering, so you can always track your nohup jobs.
What Is A Nohup Process In Linux
Nohup stands for “no hang up.” It lets you run commands that ignore the SIGHUP signal. When you log out of a terminal, Linux normally sends a hangup signal to all processes started from that session. Nohup prevents that, so your process keeps running.
You start a nohup process like this: nohup long-running-command &. The ampersand sends it to the background. But once you start it, how do you find it again? Thats where process checking comes in.
How To Check Nohup Process In Linux
Using The Ps Command To Find Nohup Processes
The ps command is your first tool. It lists running processes. To find nohup processes, you need to filter by name or parent process.
- Open a terminal.
- Run:
ps aux | grep nohup - Look for lines containing “nohup” in the command column.
This shows all processes with “nohup” in their command string. But nohup itself may not appear after the process starts. The actual command runs under a different name. So you might need to search for the specific program you launched.
Example With A Python Script
Suppose you ran: nohup python3 myscript.py &. The process will show as “python3 myscript.py” in ps output. Grepping for “nohup” wont find it. Instead, use: ps aux | grep python3 or ps aux | grep myscript.
Using Pgrep For Quick Searches
The pgrep command searches process names directly. It returns process IDs (PIDs).
- Find by name:
pgrep -a python3(shows PID and full command) - Find by pattern:
pgrep -f "myscript"(searches entire command line)
The -f flag is useful because it matches the full command string, not just the process name. This helps locate nohup processes that have weird names.
Checking Background Jobs With Jobs Command
If you are still logged into the same terminal session, the jobs command shows background processes started from that shell. But nohup processes detach from the shell. So jobs only works for processes started in the current session.
Type jobs -l to see job numbers and PIDs. This is limited, but it is the fastest way if you haven’t logged out yet.
Using Top And Htop For Real-Time Monitoring
For a dynamic view, use top or htop. These tools refresh every few seconds.
Filtering In Top
Run top then press u and type your username. This shows only your processes. Look for the command you started with nohup. Press q to exit.
Using Htop For Better Visibility
Htop is more user-friendly. Install it with sudo apt install htop (Debian/Ubuntu) or sudo yum install htop (RHEL/CentOS).
- Run
htop - Press
F4and type part of the command name - Press
F3to search forward - Press
F10to quit
Htop color-codes processes and shows CPU/memory usage. Its easier to spot your nohup process among many.
Finding Nohup Output Files
When you run nohup, output goes to nohup.out by default. Checking this file confirms the process is running and producing output.
- List files:
ls -la nohup.out - Check content:
tail -f nohup.out(follows new lines) - Check timestamps:
stat nohup.outshows last modification time
If nohup.out is updating, your process is alive. If it stopped updating, the process may have ended or is stuck.
Using Lsof To Check Open Files
The lsof command lists open files. Nohup processes often keep file handles open. You can find them by searching for the nohup output file.
Run: lsof | grep nohup.out. This shows which PID has the file open. That PID is your nohup process.
Checking Process Tree With Pstree
Nohup processes are children of the init system (PID 1) or systemd. Use pstree to see the hierarchy.
Run: pstree -p | grep -B 2 -A 2 your-username. This shows your processes and their parents. Nohup processes will have a parent PID of 1 or a session leader.
Understanding Parent Process
If a process has parent PID 1, it means its original parent (your shell) died, and init adopted it. This is a clear sign of a nohup process that survived logout.
Using Systemd To Track Services
If you run nohup processes as systemd services (using systemd-run), you can check them with systemctl.
- List user services:
systemctl --user list-units - Check status:
systemctl --user status service-name
This is more advanced but gives you logging and restart capabilities. Most nohup users stick to the basic commands.
Killing A Nohup Process
Once you find the PID, you can stop the process. Use kill PID or kill -9 PID if it doesn’t respond.
Example: kill 12345. Replace 12345 with the actual PID from ps or pgrep.
Common Mistakes When Checking Nohup Processes
- Forgetting to use
-fwith pgrep - Grepping for “nohup” when the command name changed
- Assuming jobs command works after logout
- Not checking nohup.out for updates
- Confusing zombie processes with running ones
Advanced: Using Proc Filesystem
The /proc directory contains information about every process. You can check it directly.
- List all PIDs:
ls /proc | grep -E '^[0-9]+$' - Check a specific PID:
cat /proc/PID/cmdlineshows the command - Check status:
cat /proc/PID/statusshows state, parent PID, etc.
This method is raw but powerful. It works even if ps is not available.
Automating Nohup Process Checks
You can write a script to check nohup processes periodically.
#!/bin/bash
# Check if nohup process is running
if pgrep -f "myscript.py" > /dev/null; then
echo "Process is running"
else
echo "Process is not running"
fi
Save this as check_nohup.sh, make it executable with chmod +x check_nohup.sh, and run it whenever needed.
Using Cron To Monitor Nohup Processes
Set up a cron job to check every hour.
- Edit crontab:
crontab -e - Add line:
0 * * * * /path/to/check_nohup.sh - Save and exit
The script can email you if the process is missing.
Nohup Vs Disown: What’s The Difference
Both keep processes running after logout, but they work differently. Nohup ignores SIGHUP from the start. Disown removes the process from the shell’s job table after it started.
Checking disowned processes uses the same ps commands. There is no special flag for disown.
Real-World Example: Checking A Long Backup
You ran: nohup tar -czf backup.tar.gz /data &. Hours later, you want to check.
- Run
ps aux | grep tar - Look for the tar command with backup.tar.gz
- Note the PID, e.g., 9876
- Check CPU usage:
top -p 9876 - Check output:
tail -f nohup.out
If the process is missing, it may have finished. Check nohup.out for completion messages.
Handling Multiple Nohup Processes
If you run many nohup processes, use unique output files.
Example: nohup script1.sh > script1.log & and nohup script2.sh > script2.log &. Then you can check each log file for activity.
To find all nohup processes, run: ps aux | grep -E "script1|script2".
Security Considerations
Nohup processes run with your user permissions. They can access your files. If you leave a nohup process running on a shared server, other users might see it in ps output. Use ps aux | grep username to see only your processes.
Also, nohup processes can consume resources. Monitor them regularly to avoid runaway processes.
Checking Nohup Processes On Remote Servers
If you SSH into a server, run nohup, then disconnect, you can reconnect later and check.
- SSH into the server
- Run
ps aux | grep your-command - Check nohup.out if needed
Your nohup process survived the SSH disconnection because it ignored SIGHUP.
Using Watch To Monitor Continuously
The watch command runs a command every few seconds.
Example: watch -n 2 'ps aux | grep myscript'. This updates every 2 seconds, showing you real-time changes.
Press Ctrl+C to stop watching.
Nohup And System Logs
Nohup processes don’t log to syslog by default. But you can check system logs for process exits.
Run: journalctl -u user-1000.service (replace 1000 with your UID). This shows logs for user sessions, including process deaths.
Common Questions About Nohup Process Checking
Why Can’t I See My Nohup Process In Ps Output?
You might be grepping for “nohup” instead of the actual command name. Use ps aux | grep your-command instead.
Does Nohup Process Show In Top?
Yes, it shows as a normal process. Use top -u username to filter by user.
Can I Check Nohup Process Without Sudo?
Yes, you can see your own processes without sudo. Use ps -u $USER.
What If Nohup.out Is Empty?
The process may not have produced output yet, or it redirected output elsewhere. Check the command’s error stream.
How Do I Know If Nohup Process Is Still Running?
Check for the PID in ps output. Also check if nohup.out is updating. A stale nohup.out means the process likely ended.
Conclusion
Now you know multiple ways to check nohup processes in Linux. Start with ps aux | grep command for quick checks. Use pgrep -f for precise PID finding. Monitor with top or htop for real-time data. Always verify with nohup.out timestamps. These methods work on any Linux distribution, from Ubuntu to CentOS. Practice them a few times, and you will never lose track of your background processes again.
Remember, the key is knowing what command you started. Without that, finding the process is like searching for a needle in a haystack. Write down your nohup commands or use unique output files to make checking easier.