Linux 121: Managing Services and Processes on Linux
Managing services and processes is essential for maintaining a healthy and responsive Linux system. In this guide, we'll explore how to start, stop, monitor, and manage both foreground processes and background services effectively.
1. Understanding Processes and Services
-
Processes are instances of running programs.
-
Services (daemons) are background processes that often start at boot (e.g.,
sshd
,cron
,nginx
).
Knowing how to control them allows you to maintain uptime, troubleshoot issues, and optimize resource use.
2. Managing Processes with ps
, top
, and htop
ps
– Snapshot of Running Processes
Lists all processes with useful details like PID, CPU, and memory usage.
top
– Real-Time Process Monitor
Interactive view of system resource usage. Press k
to kill a process by PID.
htop
– Enhanced Interactive Monitor
Install it if not available:
Then run:
Navigate with arrow keys, filter, and kill processes more easily.
3. Starting, Stopping, and Managing Services
Most modern Linux systems use systemd to manage services via systemctl
.
Common systemctl Commands
Enable or Disable at Boot
List All Services
4. Managing Services with init.d and service (Older Systems)
For legacy systems not using systemd:
Or directly:
5. Managing Background and Foreground Processes
Run a Process in Background
View Background Jobs
Bring Background Job to Foreground
Kill a Background Job
Or by PID:
Use kill -9 1234
to forcefully stop if needed.
6. Using nice
and renice
to Control CPU Priority
Start with Lower Priority
Change Priority of Running Process
7. Monitoring Systemd Services with Logs
Use journalctl
to view logs:
8. Auto-Restarting Services
Create or edit a systemd unit override:
Then add:
9. Conclusion
Process and service management is a critical Linux administration skill. Whether you’re diagnosing issues, optimizing system load, or automating server behavior, knowing how to interact with systemctl
, ps
, and top
will make you significantly more efficient.
Next in the series:
Linux 122: Using and Managing System Logs on Linux