Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

Check the program start time

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
zhshqzyc
Asked:
zhshqzyc
  • 4
  • 3
1 Solution
 
woolmilkporcCommented:
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
 
zhshqzycAuthor Commented:
But I don't know how to get the pid? Please advise me.
0
 
woolmilkporcCommented:
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
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
zhshqzycAuthor Commented:
[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
 
woolmilkporcCommented:
No, that's the PID of your "grep" search.

The PID is 12557
0
 
zhshqzycAuthor Commented:
Can we  just use one line or a batch file to get it?
0
 
woolmilkporcCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now