UNIX shell programming. Times function isn't working right

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 56
Reputation: kharri5 is an unknown quantity at this point 
Solved Threads: 0
kharri5's Avatar
kharri5 kharri5 is offline Offline
Junior Poster in Training

UNIX shell programming. Times function isn't working right

 
0
  #1
Feb 1st, 2006
So I have asked a couple of questions already about this shell programming, but I have another yet again.

I'm not sure why my times function in this program isn't reporting the time right. It always says that I have 0 seconds of time for a process or some giant number. I cannot get CLK_TCK to be recognized even though I included time.h and limits.h just in case. What am I doing wrong. Also I need to be getting the time of the parent process - time of the child process but am not sure it's actually the time I'm getting. If someone could help me figure this out I would much appreciate it, cause I recieve little to no direction from my teachers and TAs

Here is the code so far:

  1. void runProc(char* cmd[], int argSz)
  2. {
  3. struct tms strt, end;
  4. pid_t pid;
  5. clock_t start, finish;
  6.  
  7. // fork
  8. start = times(&strt);
  9. pid = fork();
  10. switch(pid)
  11. {
  12. case -1:
  13. cout << "Fork Failed" << endl;
  14. exit(-1);
  15. case 0:
  16. execvp(cmd[0], cmd);
  17. //iff execvp returns a value then that means it was not a proper process
  18. cout << cmd[0] << ": Command Not Found" << endl;
  19. exit(0);
  20.  
  21. default:
  22.  
  23. wait(NULL);
  24. finish = times(&end);
  25. //cout << "Process took: " <<(double) (end.tms_stime-strt.tms_stime)/CLK_TCK;
  26. //cout << " seconds" << endl;
  27. //cout << "Child has finished" << endl;
  28. }
  29. cout << "Process took: " << (finish-start);
  30. //cout << (end.tms_stime-strt.tms_stime)/CLK_TCK; //above line generates error saying must use function first
  31. cout << (end.tms_utime-strt.tms_utime);
  32. cout << " seconds" << endl;
  33. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC