Linux ps Command Tutorial List Processes with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-ps-command-tutorial-list-processes-examples/
PINTEREST
PINTEREST
INSTAGRAM

Processes are the one of the main parts of the operations systems. All user side even kernel side operations are executed with process. Process generally created, run and killed. This life cycle of the process generally the same. During this life cycle we may need to get more information about processes. ps command is most used command to list and get information about processes.

List Current User Processes

Process can be listed without providing any option to the ps command. But this will only list current users processes and do not list other system, user or root user processes.

List Current User Processes
List Current User Processes

BSD Syntax

ps command is very universal tool. ps also used other Unix variant operations systems. BSD provides options without - dash. So there is generally no difference but knowing BSD Syntax is beneficial. Following example uses BSD syntax.

List All Process

In previous steps we have listed the processes running on the Linux system just for current user. But generally we need to list all processes in a single shot. We can provide the -ax options in order to list all processes.

List All Process
List All Process
  • PID show process ID
  • TTY show running console
  • TIME  show the used CPU time
  • CMD show the complete command the thread number

List Processes As Tree

In previous example we have printed all processes in list format. There is alternative presentation format named Tree. Tree format is an hierarchical format which will provide visual information about parent and child relationship.

LEARN MORE  All About DDR4 Ram Like Frequency, Price, Performance

List Processes As Tree
List Processes As Tree

List Process Info

While listing processes we can print more information about process. We will use -u option for this detailed information.

List Process Info
List Process Info
  • UID show the User ID of process
  • PID shows the process ID
  • PPID shows the Parent Process ID
  • PRI shows Process nice value
  • STAT shows the current status of the process
  • TTY shows the current console number if connected

List Only Specific Named Process

While listing processes we may need to filter according to process or command name. Here we will use -C parameter and process name for filter operation.

List Only Specific Named Process
List Only Specific Named Process

Print Only Specific PID Process

Another way to filter processes id according to their PID. We can filter by given their PID. We will use the -p option and PID’s in order to filter.

In this example we will filter multiple processes according to their IP address.

Print Only Specific PID Process
Print Only Specific PID Process

Print Only Specific User Processes

Another useful filtering mechanism is filtering processes according to their owners or users. We will use -u option and username to filter.

In this example we want to filter username ismail .

Display Threads of Process

As we know Linux provides threads to make processes more efficient. Threads are create under the processes and completes given work by parent process. We will use --ppid option in order to list child threads.

Sort Process According To Cpu Usage

While list process by default they are sorted with their PID’s. There is alternatives to sort processes. We can sort processes according t their current CPU usage with --sort=pcpu option like below.

LEARN MORE  How To Use Linux dmesg Command To Print System Logs?

Sort Process According To Memory Usage

We can also sort processes according to their memory usage with --sort=pmem command like below.

Run Ps Real Time Mode

The default behavior of ps command is running and exiting. ps command can be run in real time without exiting. This is same as top command. We will use an external command named watch and provide the ps command.

In this example we will list processes in 2 second intervals.

Run Ps Real Time Mode
Run Ps Real Time Mode

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-ps-command-tutorial-list-processes-examples/
PINTEREST
PINTEREST
INSTAGRAM