How to debug fork()
Im writing a program which is doing some multitasking by using fork(), but I have no clue of how to debug it so that I can see what the child process is doing, I can only keep track of the parent process which is communicating with the child through a pipe, it also has a line to wait for the child process to finish, but I never see whats happening with fork() == 0. I know its a different process running somewhere else in memory but how can keep track of both of them ? I dont know how I would do it since both processes will be using the same variable names...
The only thing I get from the child(while my debugger is running the parent process) is its response, but i want to know how it decides to send me that response... |
"print" statement (in this case with own PID) is still a _major_ debugging tool.
To the same extent, log files whose names are based on PID also are. |
If you're running Linux kernel 2.6, gdb will give you complete control. Go here for details.
(This also applies if you're running HP-UX 11.x or later.) If you're running Linux kernel 2.4 or something else, I'll quote from the above link, and insert my comment in red: Quote:
If you're going to be doing stuff like this, it would do you good to browse through the complete online gdb documentation. If you use that documentation frequently, as I do, you might wish to download it from here (html tarball) or here (other formats). Hope this helps. |
All times are GMT -5. The time now is 08:04 PM. |