- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the start time of a long running Linux Process?
Whenever we want to get an update about a specific process or different process we make use of the ps command which is short for “Process status” that tells us about the state of the current process and its characteristics and a whole lot more.
When clubbed with several flags and commands we can enhance the ps command to output the start time of different processes that are running on a particular Linux machine.
The command to print the time of long running processes in increasing order is shown below −
For Ubuntu and other Linux based Systems −
ps -eo pid , lstart , cmd
For Mac OS −
ps -eo pid , lstart , command
In the above command we are trying to make use of the process state utility provided by linux and then printing the process id, along with the lstart which will provide us the date+time started and then finally the command(name) of the process.
immukul@192 linux-questions-code % ps -eo pid,lstart,command PID STARTED COMMAND 1 Fri Jun 25 23:14:44 2021 /sbin/launchd 56 Fri Jun 25 23:15:00 2021 /usr/sbin/syslogd 57 Fri Jun 25 23:15:00 2021 /usr/libexec/UserEventAgent (System)
It should be noted that the above command will print the output in the increasing order of the time and the most recent processes will be at the end of the output. In order to print the time in decreasing order we will need to make use of the sort command utility along with the above command. Consider the command shown below −
For Ubuntu and other Linux based Systems
ps -eo pid , cmd , etime | sort -n -k2
For Mac OS
ps -eo pid , command , etime | sort -n -k2
immukul@192 linux-questions-code % ps -eo pid,command,etime|sort -n -k2 1 /sbin/launchd 08-13:56:50 56 /usr/sbin/syslog 08-13:56:34 57 /usr/libexec/Use 08-13:56:34 60 /System/Library/ 08-13:56:34 61 /System/Library/ 08-13:56:34 62 /System/Library/ 08-13:56:34 65 /usr/sbin/system 08-13:56:34
- How to show historical and statistical running time of linux systems
- How can we get an ID of the running process in Java 9?
- How to create a process in Linux?
- How to Count the Number of Threads in a Process on Linux
- Linux Process Monitoring
- How to check the syntax of a Bash script without running it in Linux?
- How to list running screen sessions on Linux?
- How to get the parent process of the Process API in Java 9?
- How to Kill a Process by Name in Linux?
- Count the number of threads in a process on linux
- How to get time in milliseconds using C++ on Linux?
- How to increase the scrollback buffer in a running screen session on Linux?
- Get system start time from RuntimeMXBean in Java
- Running vs Waiting vs Terminated Process
- Windows 8 task managers running process