Solved

Check the program start time

Posted on 2011-03-16
7
424 Views
Last Modified: 2012-05-11
Hi, I run an application program yesterday, it is still running today. I want to know when the program begun. Is there a command for that?

Thanks.
0
Comment
Question by:zhshqzyc
  • 4
  • 3
7 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35149022
ps -fo etime -p pid_of_your_process

This will show you the elapsed time as

DD-HH:MM:SS

so you can easily calculate the start time.

I assume you know how to get the PID of a running process?

wmp
0
 

Author Comment

by:zhshqzyc
ID: 35149088
But I don't know how to get the pid? Please advise me.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35149127
Take the second column of

ps -ef | grep programname

I just hope you do know the name of your program (at least part of it) 'coz I will not be able to help you there.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:zhshqzyc
ID: 35149250
[testme@saguaro4 ~]$ ps -ef | grep saguaro
markv    12557 12530  0 Feb16 pts/8    00:13:49 emacs -cr maroon -ms blue -bg gray20 -fg grey90 -geometry 73x77+507+0 -font -misc-fixed-medium-r-normal--14-*-*-*-*-*-iso8859-1 -name saguaro emacs
testme   15128  5776  0 09:00 pts/4    00:00:00 grep saguaro
[testme@saguaro4 ~]$ 

Open in new window

The program is called "saguaro", so is the pid=15128?
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 50 total points
ID: 35149270
No, that's the PID of your "grep" search.

The PID is 12557
0
 

Author Comment

by:zhshqzyc
ID: 35323797
Can we  just use one line or a batch file to get it?
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 35324669
You asked for it!

Save the following script in a file named e.g. pstime, issue "chmod +x pstime".

Now determine the id of the process in question (PID) and run the script with

pstime PID

e.g.

pstime 12557

#!/bin/bash
ETIME=$(ps -f -o etime= -p $1)
if [[ -z $ETIME ]]; then
 echo "Process does not exist!"
  else
   echo "Start Time of Process with PID $1 is:"
    if echo $ETIME | grep -q "-" ; then
     date -d "01/01/1970+$(($(date +%s)-$(echo $ETIME | awk -F"[:-]" '{print ($1*86400)+($2*3600)+($3*60)+$4}'))) seconds"
    else
     date -d "01/01/1970+$(($(date +%s)-$(echo $ETIME | awk -F"[:]" '{print ($1*3600)+($2*60)+$3}'))) seconds"
    fi
fi

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Install Apache on a Mac with Homebrew | Apache Config Issues 1 183
whats a headless user in linux 3 271
how does yum update work 2 55
Ubuntu 16.04 Emergency Boot 2 189
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question