944,150 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3798
  • C++ RSS
Feb 1st, 2006
0

UNIX shell programming. Times function isn't working right

Expand Post »
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:

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 13
Solved Threads: 0
Junior Poster in Training
kharri5 is offline Offline
56 posts
since Jan 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: hi
Next Thread in C++ Forum Timeline: Fraction Class Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC