The ps command in Linux and Unix-like systems is used to display information about the currently running processes. It is used to display information about the currently running processes. It provides information such as the process ID (PID), the terminal associated with the process, the status of the process, and the command used to start the process.
Please note that the options for ps command may vary depending on the version of Linux or Unix-like systems you are using. In this article we will go over both Linux and FreeBSD variants of the ps command. For more information always refer to man ps.
Here are a few examples of how the ps command can be used:
ps -ef
ps -u username
ps -t tty
ps -p PID
ps -efH
The ps command with option -ef will show all the process running on the system, including system process and user's processes, it will show the process ID, terminal, status, and command used to start the process.
The -u option can be used to display the processes of a specific user, and the -t option can be used to display the processes running on a specific terminal. The -p option can be used to display information about a specific process. The -H option can be used to display the process hierarchy (process tree)
It's also possible to use ps command with grep to filter the output, for example:
ps -ef | grep "http"
This command will show all the process running httpd (http server) and its child processes.
It's also possible to use ps command with awk to format the output and extract specific information from the output, for example:
ps -ef | awk '{print $2}'
This command will show all the process ID of the running process.
The ps command in FreeBSD is similar to the ps command in Linux.
Here are a few examples of how the ps command can be used in FreeBSD:
ps aux
ps -U username
ps -p PID
ps -axj
The ps aux command will show all the process running on the system, including system process and user's processes, it will show the process ID, terminal, status, and command used to start the process.
The -U option can be used to display the processes of a specific user, and the -p option can be used to display information about a specific process. The -axj option can be used to display the process hierarchy (process tree)
It's also possible to use ps command with grep to filter the output, for example:
ps aux | grep "httpd"
This command will show all the process running httpd (http server) and its child processes.
It's also possible to use ps command with awk to format the output and extract specific information from the output, for example:
ps aux | awk '{print $2}'
This command will show all the process ID of the running process.
Here is another example of the ps command with awk to list specific information about the processes running by a particular user, user1:
ps -U user1 | awk '{print $1}