Linux Command to Find how Long a process is Running in UNIX
But as said, UNIX or Linux has commands for almost everything and if there is no command, you can also check some important files in the /etc directory to find out some useful info.
It’s been a long time, I have posted any UNIX or Linux command tutorial, after sharing some UNIX productivity tips. Hence, I am going to share this nice little tip, which you can use to check how long a particular process is running.
So I thought to share this nice little tip about finding runtime of a process in UNIX based systems like Linux and Solaris. In this UNIX command tutorial, we will see step by step guide to finding, since when a particular process is running in a server.
Linux Commands to find Runtime of a Process
Step 1: Find process id by using ps command like
$ ps -ef | grep java
user 22031 22029 0 Jan 29 ? 24:53 java -Xms512M -Xmx512 Server
Step 2: Find the Runtime or start time of a process
Once you found PID, you can look into proc directory for that process and check creation date, that’s the time when your process was started.
By looking that timestamp you can easily find from how long your process is running in Linux.
In order to check the timestamp of any process id procs directory, you can use following ls UNIX command with option -ld as shown below :
$ ls -ld /proc/22031
dr-x–x–x 5 user group 832 Jan 22 13:09 /proc/22031
Here process with PID 22031 has been running from Jan 22, 13:09.
If you are lucky, sometimes PS command also shows when a particular program has been started as shown in the following image:
And, if you need an alternative, you can also use
$ ps -eo pid,comm,etime | grep process_name
Where
ps: Command to report process status
-e: Select all processes
-o: Specify output format
pid: Process ID
comm: Command name
etime: Elapsed time since process start
| grep process_name: Filter for specific process
That’s all on How to find uptime for a process in Java. Yes, it’s similar to what uptime command return for a server, but you can use this to find out how long a process has been running or when exactly it was started or rebooted.
I really like these UNIX tips, as it’s a great tool to find out how long a process is running in UNIX or Linux and I have used a couple of time to check if our web server is restarted or not.
Related UNIX Command Tutorials
- 10 examples of find command in UNIX (examples)
- How to send mail with attachments from Linux? (mailx)
- 10 examples of grep command in UNIX (examples)
- 10 examples of date command in Linux (examples)
- How to get an IP address from a hostname and vice-versa in Linux (command)
- 10 examples of xargs command in Linux (examples)
- 10 examples of tar command in UNIX (examples)
- 10 examples of Vim in UNIX (examples)
- How to create, update and delete soft link in UNIX (command)
- 5 examples of sort command in Linux (examples)
- 5 examples of kill command in Linux (examples)
- 10 tips to work fast in UNIX? (tips)
- Linux find + du + grep example (example)
- 10 Examples of curl command in Linux (cURL)
- 10 Examples of chmod command in Linux (chmod)
- A Practical Guide to Linux Commands, Editors, and Shell Programming (guide)
Thanks for reading this article so far. If you like this article then please share with your friends and colleagues. If you have any questions or feedback then please drop a note.
P. S. – If you are looking for some free online courses to start your Linux journey, you should check out my list of Free Linux Courses for Programmers, IT Professionals, and System Administrators.