Skip to content

Latest commit

 

History

History
146 lines (114 loc) · 2.86 KB

File metadata and controls

146 lines (114 loc) · 2.86 KB

Process Management in Linux

Process management is crucial for monitoring and controlling system performance. Linux provides various commands to manage processes efficiently.

Running Commands in the Background & Foreground

  • Run a command in the foreground:

    ping 8.8.8.8

    This command runs ping and keeps it active in the current terminal.

  • Run a command in the background:

    ping 8.8.8.8 &

    The & symbol runs the command in the background, allowing the terminal to be free for other tasks.

  • Bringing a background job to the foreground:

    fg

    This command brings the last background job to the foreground.

  • Bringing a specific job to the foreground:

    fg 2

    This brings job number 2 to the foreground.

Viewing and Managing Jobs

  • List all background jobs in the current terminal:
    jobs

Viewing Processes with ps Command

  • Show processes running in the current shell session:

    ps
  • Display more details about running processes:

    ps -L
  • List all processes with CPU and memory usage (BSD-style format):

    ps -aux
  • List all processes using standard syntax:

    ps -e
  • Display processes in a hierarchical tree format:

    ps -axjf
  • Show processes owned by root:

    ps -U root -u root u
  • Show processes owned by a specific user (e.g., armour):

    ps -U armour -u armour

Monitoring Processes in Real-Time

  • Display real-time system processes:

    top
  • Better alternative to top: Install and use htop

    apt install htop  # Debian/Ubuntu
    yum install htop  # RHEL/CentOS
    htop
  • Show tree structure in htop:

    htop -t
  • Display processes for a specific user (e.g., armour):

    htop -t -u armour
  • Show details of a specific process by PID (e.g., 2780):

    htop -t -p 2780

Killing Processes

  • Terminate a process using its PID (e.g., 2526):

    kill 2526
  • Forcefully kill a process (e.g., 7500):

    kill -9 7500
  • Kill all instances of a process (e.g., sed):

    yum install psmisc
    killall seq
  • Kill all processes with names matching a pattern (e.g., firefox):

    killall -r firefox
  • Kill all processes owned by a specific user (e.g., armour):

    killall -u armour
  • Kill all ping processes using pkill:

    pkill ping
  • Kill all processes owned by a user (e.g., armour):

    pkill -u armour
  • Kill an exact process owned by a user (e.g., ping owned by armour):

    pkill -u armour -x ping