Skip to content

Instantly share code, notes, and snippets.

Last active September 14, 2023 04:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
ps - list processes running longer than x with name y

ps filter for Chrome processes running longer than 10 minutes (600s):

ps -e -o pid,etimes,command | awk '{ if ( $2 > 600 && $3 ~ /chrome/) print $0 }'

If the last print $0 is changed to print $1, it will just show the first column, the PID.

Copied from Nestor U. -

One liner to find processes that have been running for over 2 hours

ps -e -o pid,etimes,command | awk '{if($2>7200) print $0}'


ps: process snapshot command

-e: list all processes

-o: include only specified columns

  • pid: process id
  • etimes: elapsed time since the process was started, in seconds (note: some versions of ps do not support etimes)
  • command: command with all its arguments as a string

awk: pattern scanning and processing language

$2: second token from each line (default separator is any amount of whitespace)

7200: 7200 seconds = 2 hours

$0: the whole line in awk

Since the default action in the pattern { action } structure in awk is to print the current line, this can be shortened to:

ps -e -o pid,etimes,command | awk '$2 > 7200'

See also:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment