Created
June 12, 2020 10:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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