| | |
UNIX shell programming. Times function isn't working right
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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:
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)
void runProc(char* cmd[], int argSz) { struct tms strt, end; pid_t pid; clock_t start, finish; // fork start = times(&strt); pid = fork(); switch(pid) { case -1: cout << "Fork Failed" << endl; exit(-1); case 0: execvp(cmd[0], cmd); //iff execvp returns a value then that means it was not a proper process cout << cmd[0] << ": Command Not Found" << endl; exit(0); default: wait(NULL); finish = times(&end); //cout << "Process took: " <<(double) (end.tms_stime-strt.tms_stime)/CLK_TCK; //cout << " seconds" << endl; //cout << "Child has finished" << endl; } cout << "Process took: " << (finish-start); //cout << (end.tms_stime-strt.tms_stime)/CLK_TCK; //above line generates error saying must use function first cout << (end.tms_utime-strt.tms_utime); cout << " seconds" << endl; }
![]() |
Similar Threads
- Good books on Shell Programming/Perl (Perl)
- Shell Programming (Shell Scripting)
- Shell Programming Project (Shell Scripting)
- Implementing a unix shell running commands (Java)
- How get the Cursor Position (Shell Scripting)
- Making a UNIX Shell, so inexperienced at it (C++)
- i want help about the Simulate a Linux/UNIX shell, called MASH in the C (C)
- Bourne / Bash Unix/Linux shell scripting tutorial (Shell Scripting)
Other Threads in the C++ Forum
- Previous Thread: How to make a c++ program executable
- Next Thread: Fraction Class Program
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





