The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Can a child process return a specific value to a parent process ? Ametis1970 High Level Programming 8 04-09-2008 11:22 PM
about child process compbug UNIX for Dummies Questions & Answers 12 03-22-2006 07:55 PM
gdb to child process shriashishpatil UNIX for Advanced & Expert Users 4 12-12-2005 07:57 AM
KDM child process larryase UNIX for Dummies Questions & Answers 6 01-24-2005 05:41 PM
Child Process PID skannan High Level Programming 2 06-10-2002 07:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2007
anjul_thegreat anjul_thegreat is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 5
Time taken by a child process?

Hi,

I have a program where I fork few child jobs and call execvp to run another jobs. I use wait to wait for any job to get complete.
Requirement is I need to know the actual time taken by child job during execution.
I thought of calculating the time just before forking and after wait, but this does not gives me the actual results. I get a difference of few milliseconds using my approach.
  #2 (permalink)  
Old 07-09-2007
ilko_partizan's Avatar
ilko_partizan ilko_partizan is offline
Registered User
  
 

Join Date: Apr 2007
Location: EU, Bulgaria
Posts: 33
You can solve your problem with system call "gettimeofday" with below steps.

The steps are following:

1) The gettimeofday is called when child process begins executing.
2) The gettimeofday is called when child process finishes.
3) Then subs two results.

Best regards,
Iliyan Varshilov

Last edited by ilko_partizan; 07-09-2007 at 07:52 AM..
  #3 (permalink)  
Old 07-11-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,754
Code:
     #include <sys/times.h>

      clock_t times(struct tms *buffer);
Where struct tms is:
        struct tms {
               clock_t     tms_utime;      /* user time */
               clock_t     tms_stime;      /* system time */"
               clock_t     tms_cutime;     /* user time, children */
               clock_t     tms_cstime;     /* system time, children */
           };
struct tms has times for child processes, and is the de facto standard way to get this information.
  #4 (permalink)  
Old 07-18-2007
SharmaPCS SharmaPCS is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hyderabad
Posts: 5
How could you say there is difference?

Hi...

First read time stamp just before spawning the child process.
and read the time stamp in the child process(not in parent before wait or some other places), Calculate the difference(I hope you can do it simply)...

One thing... How can you say... you are getting different results?
(There will be difference between different runnings of the program. It is dependant on the current system image... like load on system, physical memory available on the system at that time, VM present at that time etc.)

I hope you understood what is happening and what to do...

Happy programming...
Chandu.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0