CS3841
Debugging
```gdb ./myLab3Executable```
Then, in GDB, run
```run C 1 filename.txt```
where ```C 1 filename.txt``` are the arguments for your program. 3. Your program should print the PID of the child process. 4. Open a second console, and run
```gdb```
Then, in GDB, run
```attach 4817```
where 4817 is the PID of your child process. It will immediately attach to the already-running child process and stop where the child is waiting.
General tips on using GDB. All of these must be run from the (gdb) prompt: * To see where you are in the process
```backtrace```
to see the stack and
```up```
or
```down```
to go up and down the stack. I recommend going up until you recognize something as your code. To continue running a process, type
```continue```
And to pause debugging, type the keys
<control>+<c>
* Note that the output of the child process goes to the same command prompt as the parent process. * To evaluate a variable, type
```print myVariable```
You can see which variables are in the local scope by running the commands
```info args```
and
```info locals```
* This seems to be [a nice gdb cheatsheet](https://darkdust.net/files/GDB%20Cheat%20Sheet.pdf) # Hints by Lab ## Lab 1 * See [Lab 1 Bug Fix Page](Lab1BugFix) ## Lab 4 Hints * A socket will not return 0 bytes on a read unless ALL processes (the parent and all child processes) close the writing end of the pipe. * Look at the values of your file descriptors and see if they are what you expect. * If you cannot figure out which child is keeping the process open, you can send a one-byte message through the pipe to indicate the read is complete. This is hacky, but it will work in this lab, because we always writes 32 bytes of data into the socket for the ordinary words. * To determine WHICH child you are, note that the child process inherits everything from the parent except the PID, so it has any variables distinguishing the children which the parent had either on the stack or on the heap just before the fork. So it should be EASY for a child to know which child it is. (This will become clearer as you start to write your code.)