Linux Process Management
Linux Process Management
are running on the system. Here’s a practice guide for common process management
commands.
**Commands**:
- `ps` – Display information about active processes.
- `ps aux` – Show all processes running on the system.
- `ps -ef` – Display processes in full-format listing.
- `top` – Monitor system processes in real-time.
- `htop` (if installed) – An improved version of `top` with a more user-friendly interface.
**Practice**:
- Run `ps aux` to view the list of running processes.
- Use `top` or `htop` to monitor processes in real time, and note the process ID (PID), CPU
usage, and memory usage.
---
**Commands**:
- `kill <PID>` – Send a signal to terminate a process (by default, sends SIGTERM).
- `kill -9 <PID>` – Forcefully terminate a process (send SIGKILL).
- `killall <process_name>` – Kill all processes by name.
- `pkill <process_name>` – Send a signal to a process by its name.
**Practice**:
- Run a long-running process (e.g., `sleep 500`) in the background using `sleep 500 &` and
get the PID of the process.
- Use `kill <PID>` to terminate the process.
- For more forceful termination, use `kill -9 <PID>`.
---
**Commands**:
- `&` – Add to the end of a command to run it in the background.
- `jobs` – List jobs started by the current shell.
- `fg <job_number>` – Bring a background job to the foreground.
- `bg <job_number>` – Resume a suspended job in the background.
**Practice**:
- Run a command in the background, like `sleep 300 &`.
- Use `jobs` to view background jobs.
- Use `fg %<job_number>` to bring the job to the foreground.
---
**Commands**:
- `nice <command>` – Start a process with a specific priority (default is 0, range is -20 to 19,
where -20 is the highest priority).
- `renice <priority> -p <PID>` – Change the priority of an existing process.
**Practice**:
- Start a process with a lower priority using `nice -n 10 sleep 500 &`.
- View the process's priority using `ps -l`.
- Change the priority of the process using `renice -n 5 -p <PID>`.
---
**Commands**:
- `top` – Provides a real-time view of CPU usage, memory, and other statistics for
processes.
- `ps` – Use with options like `ps aux` or `ps -ef` to see detailed process info.
- `pidstat` – Display detailed statistics about processes, including CPU, memory, and I/O
usage.
**Practice**:
- Run `top` and observe the process resource usage.
- Use `ps aux` to get more details about running processes.
---
**Commands**:
- `su <username>` – Switch user.
- `sudo <command>` – Run a command as another user (usually root).
- `chown <owner>:<group> <file>` – Change the owner of a file or process.
**Practice**:
- Use `sudo ps aux` to see processes started by root.
- Use `su <username>` to switch to another user, and start a process under that user.
---
### 7. **System Resource Usage**
- **Task**: Monitor system resource usage to see how processes impact the system.
**Commands**:
- `top` – Monitor real-time CPU, memory, and other resource usage.
- `vmstat` – Display system resource usage statistics.
- `iostat` – Report CPU and I/O statistics.
- `uptime` – Show how long the system has been running and the system load averages.
**Practice**:
- Run `vmstat 1` to see a continuous stream of system resource usage information.
- Use `iostat` to see I/O statistics for disks.
- Run `uptime` to check system load averages and uptime.
---
**Commands**:
- `ctrl + z` – Suspend a foreground process.
- `bg` – Resume a suspended process in the background.
- `fg` – Bring a background process back to the foreground.
**Practice**:
- Start a process like `nano` and suspend it with `ctrl + z`.
- Run `bg` to send the suspended process to the background.
- Use `fg` to bring it back to the foreground.
By completing this practice, you’ll gain hands-on experience with managing processes in
Linux. It will help you monitor, control, and manipulate processes effectively, ensuring smooth
system operations.