Seeing Processes
A process is one running program. Linux runs many processes at once.
Your own shell
The $$ stands for the shell itself. The answer is its name.
$ ps -o comm= -p $$List the processes
Plain ps lists the processes in this terminal. The numbers differ on every machine.
$ psOnly the names
This command prints the first five names from the whole list.
$ ps -e -o comm= | head -5Example
$ cd ~/practice
$ ps -o comm= -p $$
$ ps --ppid $$ -o pid,commKey points
- Each process has a number called a PID.
- Use ps to list processes.
- ps with no options lists the processes in the current terminal.
- The PID column holds the number of each process.
- The CMD column holds the name of each process.
- A running program and a process are the same thing.
In this example, the first command moves into the practice folder. The second command asks ps about the shell. The answer is bash. The third command lists the children of the shell. Only ps itself appears, because ps is the child that runs the list.
Note
PIDs change from run to run, so the numbers on your machine will differ.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does ps list?