![]() ![]() If( (pid_waitpid = waitpid(childpid,NULL,0) ) = -1) * NEW MODIFICATION, wait for the child!!! */ Printf("Test start_tms.tms_stime = %f\n\n",start_tms.tms_stime) Printf("Test start_tms.tms_cutime = %f\n\n",start_tms.tms_cutime) Printf("Test start_tms.tms_utime = %f\n\n",start_tms.tms_utime) NEW MODIFICATION!!! call times before fork()!!! ![]() Perhaps you could scroll back in your terminal (if it supports it), and paste the full output here for me. Hitting the enter key should give another prompt if it's not stuck. Notice I did not get another command prompt at the very end, which would make it look like the program never finishes, but in fact it has. If your ls output was long enough, it could have pushed the other stuff off the screen before you got a chance to see it. That was the output of the ls command from the child execl'ing it That was the parent process finishing and the shell giving me another command prompt. That was the output of the parent process 1 cagarvin cagarvin 7900 Oct 29 17:50 socket That was me invoking the program. 1 cagarvin cagarvin 2051 Oct 29 17:50 socket.c 1 cagarvin cagarvin 91 Oct 2 09:15 Makefile 2 cagarvin cagarvin 4096 Sep 16 00:09 Desktop 2 cagarvin cagarvin 4096 Sep 16 00:09 Documentsĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Downloadsĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Musicĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Picturesĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Publicĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Templatesĭrwxr-xr-x. 2 cagarvin cagarvin 4096 Sep 16 00:09 Videosĭrwxr-xr-x. Interestingly, the program stopped perfectly fine for me, but the output did look strange (perhaps you had a similar situation and didn't realize the program stopped. That would be the better measure of how much processing time was spent on the parent and child processes. I think once you get the waitpid call in there, you want to call times twice in the parent, once right before you fork, and once after wait returns successfully. times() only returns how much time has been used from startup to when it's called. The parent process needs to call wait or waitpid to wait for the child to finish.Īs for why the times are zero, you call times() early on in the program. After the fork, the parent may be active and finish it's tasks and exit before the control switches to the child. ![]() Once you fork, you have no guarantee that the child will fully execute before control returns to the parent (at least, as you have it written). Until you do that, it will be very difficult to troubleshoot any problems with your pipe setup.Īlso, the order in which processes are scheduled by the OS is not to be relied upon. You need to check the return value and print an appropriate error message if any of the following calls fail. }May you please help me and tell me what i'm doing wrong? nbytes = read(fd, readbuffer, sizeof(readbuffer)) }I would be glad if someone could help me and tell what i'm doing wrong Unfortunately printfs return zero, but why? * Calculate times, unfortunately return zero, but why? */ĭouble cpu_time = end_tms.tms_cutime - t1 Printf("Received Time: %f\n\n\n",t1) //prints zero Printf("Received string: %s\n\n", readbuffer) Nbytes = read(fd, readbuffer, sizeof(readbuffer)) * Parent process closes up output side of pipe */ Write(fd,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |