Unix - Process Management in Unix

Process Management in Unix

A process is any running program in Unix. Each process has a PID (Process ID) and runs in the foreground or background. Unix provides several commands to view, control, and manage processes.


1. ps (Process Status)

  • Shows information about running processes.

ps            # Shows processes in the current shell
ps -e         # Shows all processes
ps -f         # Full format (with UID, PPID, start time, etc.)
ps aux        # Shows all processes with detailed info

Example Output:

USER   PID  %CPU %MEM  COMMAND
root     1   0.0  0.1  init
user  1023   1.5  2.3  firefox

2. top (Real-Time Process Viewer)

  • Displays running processes in real time, like a task manager.

top           # Starts live process monitor
htop          # (if installed) a user-friendly version of top

You can see CPU usage, memory usage, and interactively kill processes inside top.


3. kill (Send Signal to Process)

  • Used to stop or control processes by sending signals.

kill 1234         # Kill process with PID 1234 (sends SIGTERM by default)
kill -9 1234      # Force kill (sends SIGKILL)
kill -STOP 1234   # Pause process
kill -CONT 1234   # Resume paused process

4. jobs (List Background Jobs)

  • Shows background processes started in the current shell.

sleep 100 &    # Run in background
jobs           # List background jobs

Example output:

[1]+  Running  sleep 100 &

5. fg (Foreground)

  • Brings a background job back to the foreground.

fg %1   # Bring job 1 to the foreground

6. bg (Background)

  • Resumes a suspended job in the background.

sleep 200      # Run normally
^Z             # Press Ctrl+Z to suspend
bg             # Resume job in background

7. Workflow Example

sleep 300 &       # Start process in background
jobs              # See it listed
kill %1           # Kill job 1

Or:

sleep 500
^Z                # Suspend with Ctrl+Z
bg                # Continue in background
jobs              # See it running
fg %1             # Bring it back to foreground

Summary:

  • ps → Snapshot of processes

  • top → Live monitoring

  • kill → Send signals to processes

  • jobs → List jobs in current shell

  • fg → Bring job to foreground

  • bg → Resume job in background