1

When read the manual of pstree

 -a     Show command line arguments.  If the command line of a process is swapped  out,  that  process  is
          shown in parentheses.  -a implicitly disables compaction for processes but not threads.

I am very confused about 'command line arguments'

Compare the output

me@alpha:~$ pstree |head -5
systemd-+-ModemManager---2*[{ModemManager}]
        |-NetworkManager-+-dhclient
        |                `-2*[{NetworkManager}]
        |-accounts-daemon---2*[{accounts-daemon}]
        |-acpid
me@alpha:~$ pstree -a | head -5
systemd splash
  |-ModemManager --filter-policy=strict
  |   `-2*[{ModemManager}]
  |-NetworkManager --no-daemon
  |   |-dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-wlp3s0.pid -lf...

Command lines are composed of function, options and arguments

Say -a show command line arguments, implies that others just show funtions and options, but that is not the case.

What does the command line arguments mean here?

2 Answers 2

1

Command-line arguments, in general, refers to all arguments after the name of the program being run. For example, in your command pstree | head -5, there is one argument to head which is -5.

In the pstree output, the tree consists of a root of either a pid (process ID) or init, and then the tree of children threads. For example, in your output, NetworkManager is a parent process that is running one dhclient and 2 NetworkManager threads.

Adding the -a flag also prints the arguments that were used when each process or thread was started. For example, in your output, we can see that NetworkManager was started with one argument --no-daemon, and likewise dhclient was started with several arguments.

That is all the man page means by "show command line arguments".

1
  • The thing with pstree is that for some reason it doesn't always print all the arguments.
    – x-yuri
    Mar 28, 2020 at 15:50
1

The arguments are everything that isn't the command name itself. For example, in

dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-wlp3s0.pid -lf

the arguments are all of

-d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-wlp3s0.pid -lf

These are the values at positions 1 and onwards in the C argv array given to the program when it starts, or in sys.argv[1..] in Python.

What the pstree manual is implying is that without -a it only lists the name of each program and not any of the other pieces given on the command line. That is what your two examples show: just ModemManager is listed in the first version without -a, but ModemManager --filter-policy=strict in the -a version. It doesn't care whether the "arguments" started with - or what they represented.


Sometimes programs distinguish "options" and "flags" and "arguments" and even "commands" in their documentation, but to the system they are all just arguments. The program gets given all of them together and gets to decide itself what to do with them, and which fit into each category. It can be useful to help a person think about what they're doing, but it's purely informative and not enforced. Since pstree has to show every program, it can't know how they all think about their command lines and has to be very generic.

In essence the structure of a command line is

command-name argument-1 argument-2 argument-3...

and those arguments could be -x or a sub-command or a path name, and they're all the same until command-name sees them and decides what to do. pstree sees them all in a raw form and just reports them to you when you ask for them.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .