[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Retrieving PID running time

Phil Rhoades

12/8/2005 2:32:00 PM

People,

I have found how to get PIDs etc but how can I find the running time of
a particular PID without messing around with a system call to ps etc

Thanks,

Phil.
--
Philip Rhoades

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney NSW 2001
Australia
Mobile: +61:(0)411-185-652
Fax: +61:(0)2-8221-9599
E-mail: phil@pricom.com.au




10 Answers

Joe Van Dyk

12/8/2005 3:03:00 PM

0

On 12/8/05, Philip Rhoades <phil@pricom.com.au> wrote:
> People,
>
> I have found how to get PIDs etc but how can I find the running time of
> a particular PID without messing around with a system call to ps etc

That information should be in /proc/<pid>/stat. Look at the man page
for proc for more details.


Phil Rhoades

12/8/2005 3:14:00 PM

0

On Fri, 2005-12-09 at 00:03 +0900, Joe Van Dyk wrote:
> On 12/8/05, Philip Rhoades <phil@pricom.com.au> wrote:
> > People,
> >
> > I have found how to get PIDs etc but how can I find the running time of
> > a particular PID without messing around with a system call to ps etc
>
> That information should be in /proc/<pid>/stat. Look at the man page
> for proc for more details.

Yes, but what I want (in Ruby) is something like:

ptime = Process.pid.time

How can I do that?

Thanks,

Phil.
--
Philip Rhoades

Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275)
GPO Box 3411
Sydney NSW 2001
Australia
Mobile: +61:(0)411-185-652
Fax: +61:(0)2-8221-9599
E-mail: phil@pricom.com.au




Gary Wright

12/8/2005 3:57:00 PM

0


On Dec 8, 2005, at 10:14 AM, Philip Rhoades wrote:
> Yes, but what I want (in Ruby) is something like:
>
> ptime = Process.pid.time
>
> How can I do that?

This sort of thing is very platform specific. I'm assuming
a unix/linux/macosx environment. I can't answer for Windows.

For your own process you can use Process::times, which
probably ends up calling getrusage(), a kernel system
call. See the Ruby doc for Process::times, and your system
docs for getrusage.

For the general problem of finding the information for
an arbitrary process it becomes more difficult. Some unix
systems make that sort of information available via the
/proc file system. Some make it available via the sysctl
system calls.

In either case, I don't think there is a standard Ruby library
for parsing /proc or for extracting sysctl values. You would
have to role your own.

Another hurdle is /proc and sysctl often restrict access to
programs with root privileges. So you would have to create
a setuid root ruby script to be able to read /proc or sysctl
information directly.

So if you want to get the information for an arbitrary process,
I think the quick and dirty solution is to capture the output of
ps and parse it yourself. You can use

text = `ps -l -p1234`

to get the data and then string juggling to extract the time info.



Berger, Daniel

12/8/2005 4:05:00 PM

0

gwtmp01@mac.com wrote:
>
> On Dec 8, 2005, at 10:14 AM, Philip Rhoades wrote:
>
>> Yes, but what I want (in Ruby) is something like:
>>
>> ptime = Process.pid.time
>>
>> How can I do that?
>
>
> This sort of thing is very platform specific. I'm assuming
> a unix/linux/macosx environment. I can't answer for Windows.
>
> For your own process you can use Process::times, which
> probably ends up calling getrusage(), a kernel system
> call. See the Ruby doc for Process::times, and your system
> docs for getrusage.
>
> For the general problem of finding the information for
> an arbitrary process it becomes more difficult. Some unix
> systems make that sort of information available via the
> /proc file system. Some make it available via the sysctl
> system calls.
>
> In either case, I don't think there is a standard Ruby library
> for parsing /proc or for extracting sysctl values. You would
> have to role your own.

<snip>

It's not in the standard library, but there is sys-proctable, available on the RAA.

Regards,

Dan


Joe Van Dyk

12/8/2005 5:44:00 PM

0

On 12/8/05, gwtmp01@mac.com <gwtmp01@mac.com> wrote:
>
> On Dec 8, 2005, at 10:14 AM, Philip Rhoades wrote:
> > Yes, but what I want (in Ruby) is something like:
> >
> > ptime = Process.pid.time
> >
> > How can I do that?
>
> This sort of thing is very platform specific. I'm assuming
> a unix/linux/macosx environment. I can't answer for Windows.
>
> For your own process you can use Process::times, which
> probably ends up calling getrusage(), a kernel system
> call. See the Ruby doc for Process::times, and your system
> docs for getrusage.

I thought Process::times just returned the system and user cpu time,
not the total real time since the application was started.


Joe Van Dyk

12/8/2005 5:49:00 PM

0

On 12/8/05, Philip Rhoades <phil@pricom.com.au> wrote:
> On Fri, 2005-12-09 at 00:03 +0900, Joe Van Dyk wrote:
> > On 12/8/05, Philip Rhoades <phil@pricom.com.au> wrote:
> > > People,
> > >
> > > I have found how to get PIDs etc but how can I find the running time of
> > > a particular PID without messing around with a system call to ps etc
> >
> > That information should be in /proc/<pid>/stat. Look at the man page
> > for proc for more details.
>
> Yes, but what I want (in Ruby) is something like:
>
> ptime = Process.pid.time

untested:

class Process
def meth_missing pid, *args
get_process_info(pid)[args.first]
end

def get_process_info pid
# parse /proc/<pid>/stat, put values you want into some struct and return it
end
end


Gary Wright

12/8/2005 6:01:00 PM

0


On Dec 8, 2005, at 12:44 PM, Joe Van Dyk wrote:
>
> I thought Process::times just returned the system and user cpu time,
> not the total real time since the application was started.


I assumed the OP was looking for the system/user time not the clock
time.

In any case I think you'd have to go through /proc, sysctl, or
parse the output of ps to get the starting time of a process.

I only have quick access to Mac OSX where the start time is available
via the 'lstart' keyword using ps:

$ps -p3357 -o lstart
STARTED
Thu Dec 8 00:58:42 2005
$



clairbear

5/30/2012 1:26:00 AM

0

Ron <roneal1554@att.net> wrote in
news:af231abb-1f0c-446c-8b35-e1441d3ce41d@x21g2000vbc.googlegroups.com:

> On May 29, 3:25?pm, clairbear <clairb...@msn.com> wrote:
>> Barney Frank Apologizes For Trayvon Martin Joke At Commencement
>> Speech DARTMOUTH, Mass. -- Massachusetts Congressman Barney Frank is
>> apologizing for comments he made about the Trayvon Martin case at a
>> weekend graduatio
> n
>> ceremony.
>> Referring to the hooded academic robe that civil rights leader Hubie
>> Jone
> s
>> received at the University of Massachusetts Dartmouth commencement on
>> Sunday, the Democrat said "you now have a hoodie you can wear and no
>> one will shoot at you."
>> The comment drew nervous laughter and groans from the crowd.
>> Martin was the Florida teen who was wearing a hoodie when he was shot
>> and killed by a neighborhood watch activist.
>> Frank says he made the same joke at his own expense at three other
>> graduation ceremonies.
>> He says it was meant to "ridicule the notion that a hooded sweatshirt
>> is somehow sinister."
>> Jones says he didn't think Frank meant any harm
>>
>> Funny how insensitive Libs are when they speak off script. Especially
>> whe
> n
>> they are part of one of those gruops that sreams don't discriminate
>> again
> st
>> them. ?Just imagine how the leftwing loons would be going off if it
>> was
> a
>> republican who said, but the keep there mouth shut when dems do it.
>
>
> "Funny how insensitive Libs are when they speak off script."
>
> http://lyingliar...
>
> On Rush Limbaugh the site states:
>
> "On Rush?s TV show in 1993, shortly after Clinton took office and
> year"s before Buddy joined the First Family, the show put up a picture
> of Socks, the cat. ?Did you know that the Clintons not only have a
> White House cat,? Rush said coyly, ?but they also have a White House
> dog?? Then, on screen came a picture of a thirteen-year-old Chelsea."
Rush may act the ass matter of course But he is not a Congressman, VP,
President or in other leadership position He's just a radio show
personality
> You are so full of ka-ka that you squish when you move. Grow up.
>
Soun like you have some first hand experience but please keep the
details of you abherent behaviors to youself

clairbear

5/30/2012 1:33:00 AM

0

On 29 May 2012, you wrote in alt.politics.usa:

> Ron <roneal1554@att.net> wrote in
> news:af231abb-1f0c-446c-8b35-
e1441d3ce41d@x21g2000vbc.googlegroups.com:
>
>> On May 29, 3:25?pm, clairbear <clairb...@msn.com> wrote:
>>> Barney Frank Apologizes For Trayvon Martin Joke At Commencement
>>> Speech DARTMOUTH, Mass. -- Massachusetts Congressman Barney Frank is
>>> apologizing for comments he made about the Trayvon Martin case at a
>>> weekend graduatio
>> n
>>> ceremony.
>>> Referring to the hooded academic robe that civil rights leader Hubie
>>> Jone
>> s
>>> received at the University of Massachusetts Dartmouth commencement
on
>>> Sunday, the Democrat said "you now have a hoodie you can wear and no
>>> one will shoot at you."
>>> The comment drew nervous laughter and groans from the crowd.
>>> Martin was the Florida teen who was wearing a hoodie when he was
shot
>>> and killed by a neighborhood watch activist.
>>> Frank says he made the same joke at his own expense at three other
>>> graduation ceremonies.
>>> He says it was meant to "ridicule the notion that a hooded
sweatshirt
>>> is somehow sinister."
>>> Jones says he didn't think Frank meant any harm
>>>
>>> Funny how insensitive Libs are when they speak off script.
Especially
>>> whe
>> n
>>> they are part of one of those gruops that sreams don't discriminate
>>> again
>> st
>>> them. ?Just imagine how the leftwing loons would be going off if it
>>> was
>> a
>>> republican who said, but the keep there mouth shut when dems do it.
>>
>>
>> "Funny how insensitive Libs are when they speak off script."
>>
>> http://lyingliar...
>>
>> On Rush Limbaugh the site states:
>>
>> "On Rush?s TV show in 1993, shortly after Clinton took office and
>> year"s before Buddy joined the First Family, the show put up a
picture
>> of Socks, the cat. ?Did you know that the Clintons not only have a
>> White House cat,? Rush said coyly, ?but they also have a White House
>> dog?? Then, on screen came a picture of a thirteen-year-old Chelsea."
>>
>> You are so full of ka-ka that you squish when you move. Grow up.
>
> What has that to do with the pont made?
> Why is ot OK in your mind for Barney Frank to make a joke about
Martin?
> Seems here that you are saying that it's perfectly OK.
> And just hopw is it worse for a private citizen to say something than
a
> publically elected official?
>
> Seems you don' hold much regard for the character of your elected
ones,
> but then that's really not anything new.
>
> Good to know that you really are a racist sack of shit yes?
>
>
Funny how it is OK for their lefty loonaticians to be offensive and when
you point it out all they can do is turn to a radio personality to
attack rather than refute. Fact is there are politicians on both sides
than have said offensive thing but the libs always play this holier than
thou game when one of theirs strays off message. You'sd think after
being called Barney "Fag" on the floor of congress that Barney would be
a bit more aware. I guess not

TintinX

5/30/2012 9:46:00 AM

0

On Tue, 29 May 2012 21:03:16 +0000 (UTC), "First.Post"
<OccupierDumberThanDirt@invalid.org> wrote:

>Ron <roneal1554@att.net> wrote in
>news:af231abb-1f0c-446c-8b35-e1441d3ce41d@x21g2000vbc.googlegroups.com:
>
>> On May 29, 3:25?pm, clairbear <clairb...@msn.com> wrote:
>>> Barney Frank Apologizes For Trayvon Martin Joke At Commencement
>>> Speech DARTMOUTH, Mass. -- Massachusetts Congressman Barney Frank is
>>> apologizing for comments he made about the Trayvon Martin case at a
>>> weekend graduatio
>> n
>>> ceremony.
>>> Referring to the hooded academic robe that civil rights leader Hubie
>>> Jone
>> s
>>> received at the University of Massachusetts Dartmouth commencement on
>>> Sunday, the Democrat said "you now have a hoodie you can wear and no
>>> one will shoot at you."
>>> The comment drew nervous laughter and groans from the crowd.
>>> Martin was the Florida teen who was wearing a hoodie when he was shot
>>> and killed by a neighborhood watch activist.
>>> Frank says he made the same joke at his own expense at three other
>>> graduation ceremonies.
>>> He says it was meant to "ridicule the notion that a hooded sweatshirt
>>> is somehow sinister."
>>> Jones says he didn't think Frank meant any harm
>>>
>>> Funny how insensitive Libs are when they speak off script. Especially
>>> whe
>> n
>>> they are part of one of those gruops that sreams don't discriminate
>>> again
>> st
>>> them. ?Just imagine how the leftwing loons would be going off if it
>>> was
>> a
>>> republican who said, but the keep there mouth shut when dems do it.
>>
>>
>> "Funny how insensitive Libs are when they speak off script."
>>
>> http://lyingliar...
>>
>> On Rush Limbaugh the site states:
>>
>> "On Rush?s TV show in 1993, shortly after Clinton took office and
>> year"s before Buddy joined the First Family, the show put up a picture
>> of Socks, the cat. ?Did you know that the Clintons not only have a
>> White House cat,? Rush said coyly, ?but they also have a White House
>> dog?? Then, on screen came a picture of a thirteen-year-old Chelsea."
>>
>> You are so full of ka-ka that you squish when you move. Grow up.
>
>What has that to do with the pont made?

Absolutely nothing. That's all libs have when they get caught in
their own hypocrisy.