Once fork()ed each child calls my execute_task() function and a bunch of debug info is printed. Then there are if()s to setup the pipes and/or redirection (disregard redirection for now), and finaly a call to execvp(). I have printf()s along the way but only the child process for "sort" seems to print them. I have no idea what happens to "ls", although I know it does terminate (shown below). "sort" just hangs. I think this may be some sort of pipe problem. Is an EOF sent to the reader of a pipe if the writer process closes? ...I hope I've made sense
I've attached the entire file.
Code: Select all
[Aurora:~/dev/unix] chris% rm shell ; gcc -Wall -o shell shell.c ; ./shell
shell% ls | sort
* Debug
argv[0]: "ls"
argv[1]: "(null)"
argv[2]: "(null)"
argv[3]: "(null)"
pipes[0]: 3
pipes[1]: 4
redirect[0]: -1
redirect[1]: -1
flags: 16
P_WRITE
argv[0]: "sort"
argv[1]: "(null)"
argv[2]: "(null)"
argv[3]: "(null)"
pipes[0]: -1
pipes[1]: -1
redirect[0]: -1
redirect[1]: -1
flags: 1
P_READ
1304 pstdin: 3
caught: 1303
"1304 pstdin: 3" says that the second process ("sort") has dup2()ed read pipe descriptor (3) onto it's stdin (the pipe is stored in the structure of the first process in the pipe).
there is no "1303 pstdout: 4" saying that the process for "ls" did the opposite.
"caught: 1303" shows that the first process (for "ls") has terminated.