From 9784a187d814b0ba85eea16a0320798f0f84e063 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 6 May 2022 00:17:22 +0200 Subject: [PATCH] Added notes on how to find how long a process ran to the knowledge base --- .../find how long a process has run.md | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 knowledge base/find how long a process has run.md diff --git a/knowledge base/find how long a process has run.md b/knowledge base/find how long a process has run.md new file mode 100644 index 0000000..ed7d403 --- /dev/null +++ b/knowledge base/find how long a process has run.md @@ -0,0 +1,41 @@ +# Find how long a process has run in UNIX + +UNIX and Linux have commands for almost everything; if there is no command, you can check some important files in the `/etc` directory or in the `/proc` virtual filesystem to find out some useful information. + +## The easy way + +If the program started today, `ps` also shows when: + +```sh +$ ps -ef +UID PID PPID C STIME TTY TIME CMD +user 11610 11578 0 Aug24 ? 00:08:06 java -Djava.library.path=/usr/lib/jni:/usr/lib/alpha-linux-gnu/jni... +user 17057 25803 0 13:01 ? 00:00:24 /usr/lib/chromium-browser/chromium-browser +``` + +## The hackish way + +Useful if the process started before today: + +1. find the process ID + + ```sh + $ ps -ef | grep java + user 22031 22029 0 Jan 29 ? 24:53 java -Xms512M -Xmx512 Server + + $ pgrep -l java + 22031 java + ``` + +1. look into the `proc` virtual filesystem for that process and check the creation date, which is when the process was started + + ```sh + ls -ld /proc/22031 + dr-x--x--x 5 user group 832 Jan 22 13:09 /proc/22031 + ``` + +## Sources + +- [how to find how long a process has run in unix] + +[how to find how long a process has run in unix]: https://dzone.com/articles/how-to-find-how-long-a-process-has-run-in-unix