PS Command in LInux

Linux PS Command

PS command displays directly the processes running within the linux system. However these aren’t repetitive. One only gets the update of that very moment when this command is executed. To get the continuous update we use top command.

The command also provides us the PIDs of the particular process.

The syntax for ps is as follows
ps [options]
When executed in bash or terminal, the command ps will show four coloumns. The first one refers to the PID (Process Identification Numbers) .
The second column is a TTY (Terminal type). The third column is TIME which shows the amount of CPU time that each process has taken. It may show zero if running Bash for Windows on Windows 10 like mine. The final column is the CMD which shows the command which has called the ongoing process.

Here is a screen shot ( Bash from Windows )

Further information can be grabbed by the command
ps –aux
The aux command has 3 definitions here. It is the a, u, and x. What a refers here is to list all processes, including current user as well as all the users who are currently on that system. The user can execute the command ps –u to see the users i.e. all users currently on the system.

So Run to your OS and give it a shot.

The –u option gives detail about each process running on system. The –x option gives the process which are launched during startup of the machine which are not connected nor called via terminal. Thus one cannot interrupt these process.

Here is the detailed screen shot for each of the above commands specified.

ps -aux with all columns

As we can see the columns, we have a total of eleven.
USER - It shows the list of basic users currently on the system. 

PID - It shows the identification numbers assigned to the particular user.

%CPU - It shows the share of CPU's power being used by the ongoing process 

%MEM - It shows the share of RAM being used by the user repsectively for running it's process.

VCZ - It is the Virtual Size. It is the basic permissible size for the particular process, including shared memory as well as self running addressing memory and swapped memory. SWAP memory is the memory reserved for OS Linux when RAM gets full, the pages are moved to the SWAP memory.

RSS - Resident Set Size describes the entire memory except the SWAP memory. It basically resides on the contents of RAM

STAT -  These are the Linux process State Codes.
R - Running currently on machine
T - Stopped or terminated
Z - process terminated however data hasn't been collected by the system
S - Interrupt Sleep, Process awakes when interrupted by any program
D - Un-Interrupt Sleep

Press CTRL + Z while running a process and your process will sleep until you resume it.
Press CTRL + C and the running process will terminate forcibly. 
START - The time at which the process started.

COMMAND - It shows the command executed by the user which has called that particular process alive.

TIME - It shows the duration of time that has passed while the process got activated.

Display Threads - The command which will display all the threads related to the particular process. The syntax is 
ps -p <PID No> -L

Enter the PID and one will get the threading of any particular process.
NOTE - The -e command just shows the total process running, the -f command shows details about that particular process, the -u command is for the user.
  Search a Process - This command searches the details of any process by their name. The syntax is ps -C <filename>

Process run by the user - This command shows the processes a particular user has executed. Since -u is defined as user hence we use it here
The syntax is ps -f -u <username>

PSTREE - This command shows the hierarchy of the process. It shows process of process and the links between them. The syntax is simple pstree

PS REAL TIME task manager - This will show data in terms of real time data with memory consumption, CPU consumption as well as location. It can be achieved by the watch command.
The syntax is watch -n 1 'ps -aux --sort -pmem,p-pcpu
Here the integer 1 will update the terminal stdout with a frequency of 1Hz i.e. after every 1 seconds. Replace 1 with 2 and stdout will be updated in every 2 seconds.

SORT PS - The process data and consumption can be obtained in sorted form by using --sort keyword followed by the column category which we want to be sorted.
Thus one must know the column name and it goes on by the command ps -f --sort <Column Name>
Some of the commonly used terms for Columns are 
1. PPID - Shows the parent process ID
2. PID - SHows the process identification ID
3. UTIME - User Time
4. SIZE - size
5. UID - User Id

There are further terms which can be searched though. :)   
Example Syntax ps -aux --sort -pmem

Note - PS Commands can also be used here without the hyphen or 'dash'. With dash these commands are of UNIX style and without dash these commands are of BSD style and with two dash these are of GNU style.  

Try running the command ps aux and you would get this output.

Using ps --aux may give an error "unknown gnu long option" . To be more clearly this - 

PS WITH PID Suppose we know the PID number of any particular process then it becomes easy to search about that process by entering ps -p <PID number>

PS WITH PIPELINE When the number of process grows too much in number and cannot be fit on your machine screen then the command ps aux | less can be used. Press your spacebar button to see the next entries.

Thus these commands are enough to get information about your process's details on your machine. 

No comments:

Post a Comment

Self Balancing Robot using Machine Learning

Hola Amigos, I have always loved inverted pendulums. They are very fascinating to me and I play with them a lot. In real life, I have m...