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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Integrating Redis With Message Brokers
  • Terraform State File: Key Challenges and Solutions
  • How to Reorganize and Rebuild Indexes in MS SQL?
  • Essential GitHub Enterprise Admin Commands

Trending

  • FIPS 140-3: The Security Standard That Protects Our Federal Data
  • Scaling DevOps With NGINX Caching: Reducing Latency and Backend Load
  • A Complete Guide to Modern AI Developer Tools
  • Optimizing Integration Workflows With Spark Structured Streaming and Cloud Services

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.2K 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, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Integrating Redis With Message Brokers
  • Terraform State File: Key Challenges and Solutions
  • How to Reorganize and Rebuild Indexes in MS SQL?
  • Essential GitHub Enterprise Admin Commands

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!