Time taken by a child process?


 
Thread Tools Search this Thread
Top Forums Programming Time taken by a child process?
# 1  
Old 07-09-2007
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  
Old 07-09-2007
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 08:52 AM..
# 3  
Old 07-11-2007
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  
Old 07-18-2007
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... Smilie

Happy programming...
Chandu.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting child process id for a given PID

HI Am trying to get child process id for a PID using ksh.. ps -ef | grep xntpd root 3342472 2228308 0 12:17:40 - 0:00 /usr/sbin/xntpd root 4522024 6488316 0 12:18:56 pts/0 0:00 grep xntpd root 6291614 3342472 0 12:17:40 - 0:00 /usr/sbin/xntpd Here now i... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

2. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

3. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

4. Shell Programming and Scripting

script to get child process for a process

!/bin/sh pid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $1}') sid=$(ps -Aj | grep MSTRSvr | grep -v grep | awk '{print $3}') ps -s "$sid" I am not able to get the desired output it says process list error if i use watch ps -s "$sid" it considers only the first session id (5 Replies)
Discussion started by: schippada
5 Replies

5. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

6. Shell Programming and Scripting

Child Process Name

Hi , I want to find out the child process name given its PID. I have used the ps command but it displays the parent process name against child PID. Is there any way to find out name of child program executing under any parent program? (1 Reply)
Discussion started by: sneha_heda
1 Replies

7. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

8. UNIX for Dummies Questions & Answers

doubt in child process

fork() system is used to create a child a process.lets consider fork() echo krace will print krace twice .if i give it in loop it will print krace 2 power n time..in this case all child and parent process executes same process ...but i want to create a four different child process to execute four... (4 Replies)
Discussion started by: kracekumar
4 Replies

9. UNIX for Dummies Questions & Answers

about child process

hello every one, i want to know more about creation of child process. UNDER WHAT CIRCUMSTANCES child process is created? WHAT ARE THE PREREQUISITES for a child process to be created? let us say we have a prog.c, prog.obj(compiled.c),.a\.out files. is any child PROCESS CREATED... (12 Replies)
Discussion started by: compbug
12 Replies

10. Programming

child process hang up, help!!!

Hi all, There is a pearent process with 3 child processes, they work perfect. Pearent process read from file and separate data by blocks and send it to child processes, after that pearent read the result of work and just print it out to standart output. All interprocess communication maded through... (2 Replies)
Discussion started by: prodigal
2 Replies
Login or Register to Ask a Question