DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • 7 Techniques That Supercharged My Claude-Assisted Development
  • Beyond Request-Response: Architecting Stateful Agentic Chatbots with the Command and State Patterns
  • A Beginner's Guide to Docker Compose
  • A Beginner's Guide to Essential Commands to Fix Container Setup Issues

Trending

  • Java in a Container: Efficient Development and Deployment With Docker
  • Integrating AI-Driven Decision-Making in Agile Frameworks: A Deep Dive into Real-World Applications and Challenges
  • Product-Led Software Delivery: Intelligent Platforms for DevOps at Scale
  • Liquibase: Database Change Management and Automated Deployments

How to Find How Long a Process Has Run in UNIX

Here is an easy two-step process to identify process IDs in Unix systems and then determine how long they've been running for.

By 
Javin Paul user avatar
Javin Paul
·
Updated May. 23, 19 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
77.5K Views

Join the DZone community and get the full member experience.

Join For Free

Hello everyone! Today, I am going to share a useful tip to find out how long a particular process has been running. This is very useful when you are troubleshooting an issue and want to know whether your process or service restarted fine on a daily or weekly basis.

UNIX or Linux has commands for almost everything, and if there is no command, you can check some important files in the /etc directory to find out some useful info.

So I thought to share this nice little tip to find the runtime of a process in UNIX-based systems like Linux and Solaris.

Linux Commands to Find Process Runtimes

As 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 the ps Command

$ ps -ef | grep java

user 22031 22029   0   Jan 29 ? 24:53 java -Xms512M -Xmx512 Server


Here, 22031 is the process id. By the way, if there is more than one Java process running on your server, then you might want to use a more specific grep command to find the PID.

Step 2: Find the Runtime or Start Time of a Process

Once you have the PID, you can look into proc directory for that process and check the creation date, which is when the process was started.

By checking that timestamp, you can easily find from how long your process has been running. In order to check the timestamp of any process id in the procs directory, you can use following UNIX command with the option -ld as shown below:

$ ls -ld /proc/22031

dr-x--x--x   5 user     group           832 Jan 22 13:09 /proc/22031


Here, the process with PID 22031 has been running from Jan 22, 13:09.

If you are lucky, sometimes the ps command also shows when a particular program was started, as shown in the following image:

Command (computing)

Published at DZone with permission of Javin Paul. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • 7 Techniques That Supercharged My Claude-Assisted Development
  • Beyond Request-Response: Architecting Stateful Agentic Chatbots with the Command and State Patterns
  • A Beginner's Guide to Docker Compose
  • A Beginner's Guide to Essential Commands to Fix Container Setup Issues

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook