🎓 A1Learner
🔍
0 of 50 lessons completed

Shell Processes

A process is a program that is running on the computer. The ps command lists processes, and kill stops one.

See your own shell

ps lists processes. This form shows only the current shell.

ps -o comm= -p $$

Stop a job by number

kill %1 stops job 1. The shell prints a short done line.

sleep 60 &
kill %1
echo "Sleep job stopped."

Find a process by name

ps aux lists all processes. grep keeps only the lines with the name you want.

ps aux | grep sleep

Example

ps -o comm= -p $$
sleep 60 &
kill %1
echo "Sleep job stopped."

Key points

  • Process: a program that is running on the computer.
  • Use ps to list running processes.
  • PID: the number that names one process.
  • Use kill with a job number or a PID to stop a process.
  • Use ps aux | grep to find a process by name.

In this example, ps shows the current shell is bash. A sleep job starts, then kill %1 stops it.

Note

PIDs change every time a program starts, so never trust a PID from an old listing.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does ps -o comm= -p $$ print?