stackademic

The leading education platform for anyone with an interest in software development.

Processes

View, control, and stop running programs from the terminal

Overview

Every running program is a process with a unique process ID (PID). The shell lets you list processes, monitor resource usage, and stop misbehaving programs. Knowing how to inspect and control processes helps you debug hangs, free up resources, and manage long-running tasks.

Syntax / Usage

List processes, watch them live, and send signals to stop them.

ps aux              # snapshot of all running processes
top                 # live, updating view of processes (q to quit)
kill 1234           # ask process with PID 1234 to terminate
kill -9 1234        # force-kill a process that won't stop
pkill node          # kill processes by name

sleep 60 &          # run a command in the background
jobs                # list background jobs in this shell
fg %1               # bring background job 1 to the foreground

Examples

Find a process by name to get its PID:

ps aux | grep node

Start a long task in the background and check on it:

./backup.sh &
jobs

Stop a runaway process gracefully, then forcefully if needed:

kill 4321
kill -9 4321

Common Mistakes

  • Reaching for kill -9 first; try a normal kill so the program can clean up
  • Killing the wrong PID because output shifted between listing and killing
  • Forgetting that & backgrounds a job only within the current shell
  • Assuming a closed terminal keeps background jobs alive (use nohup or a multiplexer)
  • Confusing the job number (%1) with the process ID

See Also

command-line-pipes-and-redirection command-line-environment-variables