0% found this document useful (0 votes)
8 views3 pages

Linux Process Management

Uploaded by

Shiv Jani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Linux Process Management

Uploaded by

Shiv Jani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Linux process management involves monitoring, controlling, and managing processes that

are running on the system. Here’s a practice guide for common process management
commands.

### 1. **View Running Processes**


- **Task**: List processes running on the system.

**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.

---

### 2. **Killing or Stopping a Process**


- **Task**: Terminate a process using its process ID (PID).

**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>`.

---

### 3. **Running Processes in the Background**


- **Task**: Run a command in the background and bring it back to the foreground.

**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.

---

### 4. **Process Priorities**


- **Task**: Change the priority of a process.

**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>`.

---

### 5. **Process Information**


- **Task**: Gather detailed information about processes.

**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.

---

### 6. **Process Ownership and Switching**


- **Task**: Change the user that owns a process.

**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.

---

### 8. **Background and Foreground Process Management**


- **Task**: Switch processes between foreground and background.

**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.

You might also like