Sunday, April 30, 2017

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

Further Learning
Linux Command Line Interface (CLI) Fundamentals
Linux System Administration Fundamentals
How Linux Works: What Every SuperUser Should Know

Related UNIX Command Tutorials
  • 10 examples of find command in UNIX (examples)
  • 10 examples of grep command in UNIX (examples)
  • 10 examples of date command in Linux (examples)
  • How to get IP address from 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 examples of chmod command in UNIX (examples)
  • 10 tips to work fast in UNIX? (tips)

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.


Hemanth said...

What is 23017 in this command ?
$ ls -ld /proc/20317

Anonymous said...

man ps ...

ps -o pid,etime,start,args

20317 is a PID. Each PID has a corresponding entry under /proc.

Anonymous said...

I think the question Hemanth is asking was not command run in this example ls -ld /proc/22031 not ls -ld /proc/20317

Post a Comment