Reputation: 617
I have a already written script which has this line PID = ps -e -o user:20,pid,cmd
Could anybody explain me the meaning of this line? I am bit confused with user:20 part
Thanks!
Upvotes: 0
Views: 1766
Reputation: 6525
ps - This command report a snapshot of the current processes.
-e , This options helps to select all processes.Identical to -A.
-o , This options helps to specify user-defined format.
user:20 , This will help to format the output of ps command.The user:20 will add some extra 20 space character betweens the columns. Below the example will help you to find the difference.
jdeveloper@jdeveloper ~ $ ps -e -o user:20,pid
USER PID
root 2926
jdeveloper 2948
root 3255
root 3570
root 3802
jdeveloper 3825
jdeveloper 3860
Now , lets try with 10 character space padding in response.
jdeveloper@jdeveloper ~ $ ps -e -o user:10,pid
USER PID
root 2926
jdeveloper 2948
root 3255
root 3570
root 3802
jdeveloper 3825
jdeveloper 3863
Find more about ps command using man command.Try
jdeveloper@jdeveloper ~ $ man ps
Hope it will help you.
Upvotes: 0
Reputation: 410
From ps
's man page:
-o format
User-defined format. format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify
individual output columns. The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps
-o pid,ruser=RealUser -o comm=Command) as desired. If all column headers are empty (ps -o pid= -o comm=) then the header line will not be
output. Column width will increase as needed for wide headers; this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-
WCHAN-COLUMN -o comm). Explicit width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps -o pid=X,comm=Y varies with
personality; output may be one column named "X,comm=Y" or two columns named "X" and "Y". Use multiple -o options when in doubt. Use the
PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that may be used to choose the default UNIX or
BSD columns.
Explicit width control (ps opid,wchan:42,cmd) is offered too.
So you'll get a user
column with 20-char's width.
Upvotes: 1
Reputation:
ps
is a command name used to show processes running in the system currently.
-e
is a "short" option which means that all processes should be listed.
-o user:20,pid,cmd
is an option which sets expected format of lines to be printed on screen, i.e. we want the first column to contain usernames (who own the processes) padded to 20 characters, the second column to show process IDs and the third column to contain command names which have been used to start the processes. Just that.
Also, you can simply try to run this yourself in your terminal: ps -e -o user:20,pid,cmd
and see what happens.
Upvotes: 2