GoAdmio

top

Show the ten most CPU-hungry processes with the command of each one's parent, or look up the parent of a single process

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

The standard Linux top shows which processes use the most CPU, but not what started them. /go/top adds that. For each of the ten busiest processes, it prints the process ID and the full command of its parent process. This helps you tell, for example, which PHP-FPM master or web server a busy worker belongs to.

You can also give it a single process ID to get that process's parent.


Quick start

# The ten busiest processes and their parents
/go/top

# The parent of one process
/go/top 1234

Syntax

/go/top [<pid>]

[!NOTE] This is not the system top command. Call it as /go/top to avoid mixing the two up.


Options

Argument Required Default Notes
<pid> No The ten busiest processes A process ID (a whole number above 0).

If the argument is not a positive number, the command prints nothing.


Output

Each line has the form PID|parent command. The command is the parent's full command line.

2345|/usr/sbin/php-fpm: master process (/etc/php-fpm.conf)
2411|/usr/sbin/httpd -DFOREGROUND
2790|/usr/lib/systemd/systemd --system --deserialize 31

The lines are in the order of top: highest CPU use first.

When a parent can't be found, the line is written to the error output instead:

1|(parent process not found or invalid)
Outcome What you get
Parent found `PID
Parent not found `PID
Invalid <pid> No output.

Every run is logged to /var/log/go/top.log with a timestamp and the arguments used.


Examples

# Top ten processes with their parents
/go/top
# Only the results, without the "not found" lines
/go/top 2>/dev/null
# Find out what started process 2345
/go/top 2345

Troubleshooting

Symptom Likely cause Fix
No output when you pass a PID The argument isn't a whole number above 0. Pass a valid PID.
(parent process not found or invalid) The process has ended, doesn't exist, or has no parent (process 1). Nothing to fix. Check the PID with ps -p <pid>.
The parent is systemd The process is a service started directly by systemd. This is expected for daemons. The output is most useful for worker processes, such as PHP-FPM workers or scripts run by a web server.
A top or bash process is in the list The command's own top run is among the busiest processes for a moment. Ignore it.
The list differs from the live top The command takes a single snapshot, which is less accurate than a screen that refreshes. Run it again, or watch live with the system top.
Fewer than ten lines Some processes ended before their parent was looked up, and those lines went to the error output. Run with 2>&1 to see them.

Details

  1. Runs top once in batch mode (top -b -n 1). By default, top sorts by CPU use.
  2. Takes the process IDs from the first ten process lines.
  3. For each process, reads its parent's process ID with ps.
  4. Prints the process ID and the command line of the parent.

With a <pid> argument, steps 1 and 2 are skipped and only that process is looked up.

The command only looks up one level. It shows the parent, not the whole chain of ancestors.

Item Used for
top, ps, awk, xargs Finding the processes and their parents.
/var/log/go/top.log The command log.

See also

Command Description
cpu Check the top ten CPU-consuming commands or services
mem Check the top ten memory-consuming commands or services
loadavg Check the weekly server load average
httptop Display active HTTP requests in real time
mysqltop Identify the most accessed databases on a GoAdmio server
heal Check GoAdmio service status and fix issues