Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Linux and Unix Usefull command | How to Find Runtime of a Process in UNIX and Linux

 So you checked your process is running in Linux operating system and it's running find, by using ps command. But now you want to know, from how long process is running, What is start date of that process etc. Unfortunately ps command in Linux or any UNIX based operating system doesn't provide that information. But as said, UNIX has commands for everything, there is a nice UNIX tip, which you can use to check from how long a process is running. It’s been a long time, I have posted any UNIX or Linux command tutorial, after sharing some UNIX productivity tips . So I thought to share this nice little tip about finding runtime of a process in UNIX based systems e.g. Linux and Solaris. In this UNIX command tutorial, we will see step by step guide to find, since when a particular process is running in a server.


Commands to find Runtime of a process in UNIX
UNIX command to find runtime of a process in LinuxAs I said, there is no single command, which can tell us that from how long a process is running. We need to combine multiple commands, and our knowledge of UNIX based systems to find uptime of a process.

Step 1 : Find process id by using ps command e.g.

$ ps -ef | grep java
user 22031 22029   0   Jan 29 ?          24:53 java -Xms512M -Xmx512 Server

here 22031 is process id or PID. By the way if there are more than one Java process running in your server, than you might want to use a more specific grep command to find PID. Anyway, 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 timestamp of any process id proc directory, you can use following ls UNIX command with option -ld as shown below :

$ ls -ld /proc/20317
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.

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. I really like this UNIX tips, as it's a great tool to find from how long a process is running in UNIX or Linux