LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-15-2011, 09:09 AM   #1
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Rep: Reputation: 1
Question command to find out for how many Milli seconds a process is been running


Hi,

Is there any command to find out for how many Milli seconds a process is been running?

ps -a -o pid,etime | grep "process pid" gives the time in min:seconds. I wanted in milliseconds . Please help.

Thanks,
msh.
 
Old 02-15-2011, 09:20 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
the time command.

Code:
$ time sleep 5

real    0m5.009s
user    0m0.000s
sys     0m0.000s
But when I use it with pipes, it only seems to time the first command.
 
Old 02-15-2011, 09:30 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,
Quote:
Originally Posted by MTK358 View Post
But when I use it with pipes, it only seems to time the first command.
This should work with pipes:

time ( ps -a -o pid,etime | grep "process pid" )

Hope this helps.
 
1 members found this post helpful.
Old 02-18-2011, 01:03 PM   #4
mshforever
LQ Newbie
 
Registered: Nov 2010
Posts: 7

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by druuna View Post
Hi,
This should work with pipes:

time ( ps -a -o pid,etime | grep "process pid" )

Hope this helps.
Thanks.
 
Old 02-18-2011, 01:11 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by druuna View Post
Hi,
This should work with pipes:

time ( ps -a -o pid,etime | grep "process pid" )

Hope this helps.
How do you explain this:

Code:
$ time (sleep 1 | sleep 1)

real    0m1.001s
user    0m0.000s
sys     0m0.000s
 
Old 02-18-2011, 01:12 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome
 
Old 02-18-2011, 01:12 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by druuna View Post
You're welcome
What do you mean by that?
 
Old 02-18-2011, 01:16 PM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Actually you're correct, druuna. It does work.

It's just that using the pipe doesn't cause the second sleep to run after the first one: they run at the same time.

Code:
$ time (sleep 1 | sleep 1)

real    0m1.001s
user    0m0.000s
sys     0m0.000s
$ time bash -c 'sleep 1 | sleep 1'

real    0m1.005s
user    0m0.003s
sys     0m0.000s
$ time bash -c 'sleep 1 ; sleep 1'

real    0m2.006s
user    0m0.003s                                                    
sys     0m0.000s
$ time (sleep 1 ; sleep 1)

real    0m2.002s
user    0m0.000s
sys     0m0.000s
 
Old 02-18-2011, 01:16 PM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,
Quote:
Originally Posted by MTK358 View Post
How do you explain this:

Code:
$ time (sleep 1 | sleep 1)

real    0m1.001s
user    0m0.000s
sys     0m0.000s
sleep 1 | sleep 1 isn't a proper command..... But: The output of sleep 1 is piped to sleep (and the 1 is ignored), which takes 1 second.

Code:
$ time (sleep 2 && sleep 2)

real    0m4.002s
user    0m0.000s
sys     0m0.003s
Hope this helps.
 
Old 02-18-2011, 01:17 PM   #10
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
See my previous post, I think you posted while I was writing it.
 
Old 02-18-2011, 01:18 PM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by MTK358 View Post
What do you mean by that?
Not meant for you, but for mshforever's reply (I'm slow or you are fast...)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] jbd2/sda1-8 What exactly is this process that keeps running every few seconds? damgar Linux - Software 5 10-13-2015 11:23 AM
find process running uncommanded aal Linux - Security 9 01-19-2008 08:43 PM
Need to find which processor is running a process demosp Linux - General 3 11-06-2007 08:34 PM
Trying to get ps to display time a process has been running in seconds kinetik Programming 1 02-26-2007 08:21 PM
how to find out what serivces/process are running in fedora yinglcs Linux - General 2 03-06-2006 11:40 AM


All times are GMT -5. The time now is 12:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration