Report information of processes: zero to hero
Detailed information about processes, which one would choose ?
$ ps aux
$ ps -aux
$ ps -ef
Thus, “ps -aux” will fail (unless you want to know about user “x”). As a convenience, however, “ps aux” still works as it did in Tiger.
ps (process status) accepts several kinds of option
- Unix options: which must be preceded by
—
and may be grouped - BSD options: which must not be preceded by
—
and may be grouped - GNU-style long options: each of which must be preceded by
--
Coming back to the original question:
Go for *BSD-style approach and display all processes of all users and also lift the BSD-style “must have a tty” restriction
$ ps auxf
just throw anf
in order to see the ancestry tree
- when you want : VSZ (virtual memory size of the process [KiB]), RSS(resident set size, the non-swapped physical memory that a task has used) and %CPU (cpu utilisation of the process)
Or you can go for *UNIX-style approach and display all processes (daemons to) using BSD long format with full listing
$ ps -elf
- when you want :PPID(parent process ID), NI(nice value), C(processor utilisation)
Go even further, customise your output:
Specified user-defined format, e.g. PPID, PID, Elapsed time, Percentage Memory Usage, : $ ps e -o ppid,pid,etime,command,pmem,cpu
Or you can add columns besides the default ones e.g: Elapsed time and ratio of the process’s resident set size to the physical memory on the machine:
$ ps -ef -O etime,pmem,command
ps -ef -O etime,pmem,command
Now let’s put it to work:
- List processes of a certain user:
$ ps -u <user_name>
(user ID or user name) - List all processes by executable name:
$ ps -C <executable_name>
3. Sort the output of ps based on memory usage: $ ps aux --sort=-%mem
4. Get the PID of the current process: $ echo $$
5. List open files by a process: $ lsof -p <PID>
6. Determine which process (PID) has open a file: $ fuser <file>
or $ lsof -t <file>
Sources: