Back to course

Process Management: ps, kill, Background Tasks

Termux Masterclass: From Zero to Linux Power User on Android

15. Process Management: ps, kill, Background Tasks

Processes are running instances of programs. Managing them is crucial for stability and resource control.

1. Listing Running Processes (ps)

ps lists currently running processes. The standard flags for Linux are often used:

  • ps aux: (Not fully supported in Termux's minimalist environment)
  • ps -ef: Displays all processes in full format.

bash $ ps -f UID PID PPID C STIME TTY TIME CMD u0_a... 1234 1200 0 10:00 ? 00:00:00 /usr/bin/bash ...

The most important column is PID (Process ID), a unique number for each running program.

2. Backgrounding and Foregrounding Jobs

If you start a program that takes a long time, you can send it to the background by adding an ampersand (&) at the end of the command.

bash

Start a script in the background

$ ./long_running_script.sh & [1] 12345

  • jobs: Lists background jobs. [1] is the job number.
  • fg %1: Brings job number 1 back to the foreground.
  • bg %1: Resumes a suspended job (suspended via Ctrl+Z) in the background.

3. Terminating Processes (kill)

If a program is frozen or running unnecessarily, you can stop it using kill along with its PID.

bash

Example: kill the process with PID 12345

$ kill 12345

Note on Signals: By default, kill sends signal 15 (SIGTERM), asking the program to shut down gracefully. If it doesn't respond, you use signal 9 (SIGKILL), which forces immediate termination:

bash $ kill -9 12345