Using the “ps” command
The ps command can be used on its own. It will output four columns of information:
PID: the unique identifier of the process defined by the system. It’s the value that we use to stop a process.TTY: terminal from which the process was started.TIME: the total amount of CPU time used by the process.CMD: command that generates the process
Note that when you use the command without any options, it doesn’t show you much information. Here are a few ways to make it more useful.
1. List the process of all users
When some programs are installed, they sometimes also create some additional users to run the process. To list the processes of the users, use the -e option: and its output:
2. List process with more information
It’s possible to have more information when you list the running process. To do this, you can use the ef option. and its output:
3. Filter the Process by Process ID
If you know the process ID of the running process you want to show, you can filter for it specifically with the -p flag. This can take multiple PIDs as arguments, separated by a single comma and no space.
4. List the processes owned by a user
You can also list the processes that are owned by a user with the u option followed by the name of the user: and its output:
5. List the actives processes
It’s possible to list all the processes that are active by using the ax option: and its output:
6. List the active processes with the users
It’s possible to list all the active processes with the users when you add the -aux flag: and its output:
7. Filter the process by the name of a program
It’s possible to retrieve the information about a specific program that is running by applying a filter on the ps result: and its output: Alternatively, you can also use the C option to filter the process by its name:
8. Display Specific Columns
In addition to the four default columns, you can get ps to display an additional column of information. For example: The -o flag sets specific output display options for the ps command’s results. See a full list of standard display options for ps.
9. Display Results in Hierarchical Tree Style
This uses ASCII art to create a tree-style structure for displaying processes. Shows forked and children processes as descendants of the appropriate parent processes, sorting to match. To hide the “branches” of the tree, use -H in place of –forest.
10. Display Process Threads
The -L flag toggles on a threaded display for any functionality of ps. It’s most useful when tracking down the threads of a specific process.
11. Show All Root Processes
Execute a search for all processes running with real and effective root identifications. This shows them in the full-length format, thanks to the -f flag. You can combine it with the -o flag to customize output.
Use the kill command to stop a process
Once you have located the misbehaving process, you can use the kill command to kill a process that is running. The command sends a signal to a process that terminates it. When your programs are frozen, most of the time you will need to forcefully kill them with the -9 option. The output of ps is an instant view. Unlike htop, It does not update itself dynamically. This means you might have to run it multiple times to get a clear picture of which process is misbehaving. To get an up-to-date view of the processes, you can try some other commands for the Linux system.