Wednesday, January 15, 2025

Linux 101: Part 6 - Process and Job Management in Linux

In the sixth part of our Linux 101 series, we will explore process and job management in Linux. Understanding how to manage running processes is crucial for system administration, troubleshooting, and optimizing system performance.

Understanding Linux Processes

A process is a running instance of a program. Every process in Linux is assigned a unique Process ID (PID) and belongs to a user.

Types of Processes:

  • Foreground processes: Run in the terminal and require user interaction.
  • Background processes: Run in the background without user interaction.
  • Daemon processes: System processes that run in the background (e.g., SSH, cron jobs).

Viewing Running Processes

Use these commands to monitor running processes:

  • View active processes:
    ps aux
    
  • View processes dynamically:
    top
    
    or use an improved version:
    htop
    
  • View processes for a specific user:
    ps -u username
    
  • Find a specific process by name:
    ps aux | grep processname
    

Managing Processes

Killing a Process

  • Terminate a process by PID:
    kill PID
    
  • Force kill a process:
    kill -9 PID
    
  • Kill a process by name:
    pkill processname
    
  • Kill all instances of a process:
    killall processname
    

Changing Process Priority

Every process has a priority value called nice value (ranges from -20 to 19, where -20 is the highest priority and 19 is the lowest).

  • Start a process with a lower priority:
    nice -n 10 command
    
  • Change priority of a running process:
    renice -n 5 -p PID
    
  • Check priority of running processes:
    ps -eo pid,comm,nice
    

Managing Jobs in Linux

Linux allows job control to manage multiple processes in the terminal.

Running and Controlling Jobs

  • Run a command in the background:
    command &
    
  • View background jobs:
    jobs
    
  • Bring a background job to the foreground:
    fg %jobID
    
  • Suspend a running process: Press Ctrl + Z
  • Resume a suspended job in the background:
    bg %jobID
    
  • Terminate a background job:
    kill %jobID
    

Monitoring System Performance

Use these commands to analyze CPU, memory, and process usage:

  • Check system resource usage:
    vmstat 5
    
  • Monitor memory usage:
    free -m
    
  • View disk usage:
    df -h
    
  • Check I/O performance:
    iostat
    

Conclusion

Managing processes and jobs is essential for system stability and efficiency. In the next part, we will explore Linux Shell Scripting and Automation, which will help you automate tasks and improve productivity.

Stay tuned for Linux 101: Part 7 – Shell Scripting and Automation in Linux!

0 comments: