Skip to content

Instantly share code, notes, and snippets.

@nestoru
Created June 12, 2020 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nestoru/91be7486807350bcd2cc0f7b368ff2f8 to your computer and use it in GitHub Desktop.
Save nestoru/91be7486807350bcd2cc0f7b368ff2f8 to your computer and use it in GitHub Desktop.
One liner to find processes that have been running for over any amount of seconds
# One liner to find processes that have been running for over any amount of seconds
SECONDS=$1
ps -e -o "pid,etimes,command" | awk '{if($2>$SECONDS) print $0}'
: '
Explanation:
===========
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
command: command with all its arguments as a string
awk: pattern scanning and processing language
$2: second token from each line (default separator is space)
7200: 7200 seconds = 2 hours
$0: the whole line in awk
More:
=====
man ps
man awk
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment