Operating System - HP-UX
1827286 Members
1657 Online
109717 Solutions
New Discussion

CPU time and elapsed time

 
SOLVED
Go to solution
Kris_5
Occasional Advisor

CPU time and elapsed time

Hi Floks,

How do I find the time elapsed, CPU time taken for a child process. With timex I am getting real time, but how do I find the CPU time.

TIA

Kris
7 REPLIES 7
Jeff Schussele
Honored Contributor

Re: CPU time and elapsed time

Hi Kris,

If you know the Process ID (PID) - you can do:

#ps -ef | grep PID

And the TIME column will list cumulative execution time.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Helen French
Honored Contributor

Re: CPU time and elapsed time

Hi,

Use 'top' command. Check the "TIME" parameter, that will tell you the number of system and CPU seconds the process has consumed.

You can use Glanceplus too and check the process reports:

# gpm

HTH,
Shiju
Life is a promise, fulfill it!
Jeff Schussele
Honored Contributor

Re: CPU time and elapsed time

Kris,

Of course both of these are "real-time" & not elapsed or after the fact times.

If you want those you'll need to install & activate Accounting & then use the acctcom command that searches the /var/adm/pacct file & grep for the command you ran & in here can be found (CPU secs) values.

See the acctcom docs:

http://docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/B2355-90129/B2355-90129_top.html&con=/hpux/onlinedocs/B2355-90129/00/00/8-con.html&toc=/hpux/onlinedocs/B2355-90129/00/00/8-toc.html&searchterms=acctcom&queryid=20020411-121554

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Kris_5
Occasional Advisor

Re: CPU time and elapsed time

Hi All,

Thanks for the suggestions. At the moment we haven't installed accounting software (our system engineer thinks it is very much overhead..), so I am trying to find other ways.

Here the example (only) of my case.

$ cat a.sh
#!/bin/sh
echo "xxxx"
sleep 60

$cat b.sh
#!/bin/sh
timex 2>rtime.log a.sh

The b.sh is submitted through cron, so I can't use top or ps -ef effectively.

Kris
Paula J Frazer-Campbell
Honored Contributor

Re: CPU time and elapsed time

Kris

Try:-

ps -ef | grep "scriptname" >/tmp/timerlog

Place this at secont to last line.

Run it and the cat the timerlog.

HTH

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: CPU time and elapsed time

Kris

To pick up the pid of your running programme,
within the program:-

runpid=`ps -ef | grep | awk '{print $2}'

echo $runpid


Paula
If you can spell SysAdmin then you is one - anon
Frank Slootweg
Honored Contributor
Solution

Re: CPU time and elapsed time

Perhaps (probably? :-)) I do not understand the question, but the sum of the "user" and "sys" times reported by timex(1) *are* the CPU time.

Some examples:

$ # Hardly any CPU time, i.e. user and sys are (nearly) zero :
$ timex sleep 5

real 5.02
user 0.00
sys 0.01

$ # Nearly all CPU time, i.e. user + sys ~ real:
$ cat ./doit
#! /usr/bin/sh

count=0

while [ count -le 100000 ]
do
((count=count+1))
done
$ timex ./doit

real 8.44
user 5.95
sys 2.48

$