Tracking ongoing processes
ps (Process status) can be used to see/list all the running processes.
$ ps PID TTY TIME CMD 19 pts/1 00:00:00 sh 24 pts/1 00:00:00 ps
For more information -f (full) can be used along with ps
$ ps –f UID PID PPID C STIME TTY TIME CMD 52471 19 1 0 07:20 pts/1 00:00:00f sh 52471 25 19 0 08:04 pts/1 00:00:00 ps -f
For single-process information, ps along with process id is used
$ ps 19 PID TTY TIME CMD 19 pts/1 00:00:00 sh
For a running program (named process) Pidof finds the process id’s (pids)
Fields described by ps are described as:
- UID: User ID that this process belongs to (the person running it)
- PID: Process ID
- PPID: Parent process ID (the ID of the process that started it)
- C: CPU utilization of process
- STIME: Process start time
- TTY: Terminal type associated with the process
- TIME: CPU time is taken by the process
- CMD: The command that started this process
There are other options which can be used along with ps command :
- -a: Shows information about all users
- -x: Shows information about processes without terminals
- -u: Shows additional information like -f option
- -e: Displays extended information
Stopping a process:
When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For processes running in background kill command can be used if it’s pid is known.
$ ps –f UID PID PPID C STIME TTY TIME CMD 52471 19 1 0 07:20 pts/1 00:00:00 sh 52471 25 19 0 08:04 pts/1 00:00:00 ps –f $ kill 19 Terminated
If a process ignores a regular kill command, you can use kill -9 followed by the process ID.
$ kill -9 19 Terminated
Processes in Linux/Unix
A program/command when executed, a special instance is provided by the system to the process. This instance consists of all the services/resources that may be utilized by the process under execution.
- Whenever a command is issued in Unix/Linux, it creates/starts a new process. For example, pwd when issued which is used to list the current directory location the user is in, a process starts.
- Through a 5 digit ID number Unix/Linux keeps an account of the processes, this number is called process ID or PID. Each process in the system has a unique PID.
- Used up pid’s can be used in again for a newer process since all the possible combinations are used.
- At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process.