Process Management in Linux: Understanding and Controlling System Resources

Welcome back to our Linux learning series! In the last article (click here to read), we explored Linux file systems, permissions, etc. using examples. Today, we’ll dive into Linux process management, an essential part of understanding and using Linux effectively.
Managing processes is an essential skill in Linux. Processes are the backbone of every application running on your system, whether in the foreground or background. Understanding how to monitor, control, and optimize them will give you the ability to manage system resources effectively.
This article provides a detailed overview of processes, tools for monitoring them, managing process priorities, sending signals, and automating tasks with cron jobs. Let’s dive in!
What Are Processes in Linux?
A process is a program in execution. When you execute a command, an instance of that program runs as a process. Each process has a unique identifier called the Process ID (PID).
Types of Processes in Linux:
- Parent Process: Every process is spawned by another process, known as its parent process. The parent process has its own PID.
- Child Process: A process created by another process. It inherits some attributes from the parent.
Lifecycle of a Process:
- Creation: A process is created using the
fork()
system call. - Execution: The process executes its instructions.
- Termination: The process exits using the
exit()
system call.

Foreground vs. Background Processes
Foreground Processes
These run interactively and occupy the terminal until they finish. Example:
nano file.txt
Background Processes
These run in the background, allowing the terminal to be used for other tasks. To run a process in the background, append &
to the command:
python script.py &
Managing Background Processes
- List background jobs:
jobs
- Bring a background job to the foreground:
fg %1
- Send a foreground process to the background:
Ctrl+Z
bg
Monitoring Processes with Tools
Linux provides powerful tools to monitor and manage processes.
1. top
Shows a dynamic, real-time view of system processes.
top
2. htop
An interactive process viewer with a user-friendly interface. Use arrow keys to navigate and F9
kill processes. Install it with:
sudo apt install htop
3. ps
Displays information about active processes.
ps aux
4. kill
Sends signals to processes, like terminating them. Example:
kill -9 <PID>

4. Signals in Linux
Signals are used to communicate with processes. Some common signals:
- SIGKILL (9): Forcefully terminates a process.
- SIGTERM (15): Politely asks a process to terminate.
- SIGHUP (1): Reloads the configuration without terminating.
Example: Sending a Signal
kill -9 <PID>
Process Priority with nice
and renice
What is Process Priority?
Linux uses a priority-based scheduling system. Higher-priority processes get more CPU time.
Adjusting Priority with nice
Run a process with a specific priority:
nice -n 10 python script.py
The -n
value ranges from -20
(highest priority) to 19
(lowest).
Changing the Priority of Running Processes with renice
renice -n 5 -p <PID>
Creating and Managing Cron Jobs
Cron jobs automate recurring tasks like backups, log cleanup, or email notifications.
Setting Up Cron Jobs
- Open the cron table (crontab):
crontab -e
2. Add a cron job using the following syntax:
* * * * * /path/to/command
- The five
*
represent minute, hour, day of month, month, and day of week.
Example: Automating a Log Cleanup Task
Suppose you want to delete files older than 7 days from /var/log
:
# Add this line to crontab
0 3 * * * find /var/log -type f -mtime +7 -exec rm {} \;
This command runs at 3:00 AM every day.

Practical Example: Automating a Log Cleanup Task
- Create a Shell Script:
#!/bin/bash
find /var/log -type f -mtime +7 -exec rm {} \;
Save it as cleanup_logs.sh
.
- Make it Executable:
chmod +x cleanup_logs.sh
- Schedule the Task with Cron:
crontab -e
Add the following line to schedule the script to run every Sunday at 1 AM:
0 1 * * 0 /path/to/cleanup_logs.sh
Tips for Efficient Process Management
- Regularly monitor resource usage with
htop
. - Use
nice
andrenice
to ensure critical processes get enough CPU time. - Automate repetitive tasks with cron jobs to save time.
- Always gracefully terminate processes
SIGTERM
before usingSIGKILL
.
Conclusion
This article covered the essentials of process management in Linux, from understanding process types to managing priorities and automating tasks with cron jobs. With these tools and techniques, you’ll be well-equipped to manage system resources efficiently, troubleshoot issues, and streamline workflows.