ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I'm writing a small C program that forks(), dups(), and execve()s an X application that reads its input from its stdin (as opposed to params).
I can spawn it and its definitely running, however the parent process waits for input and never gets it as the X application is waiting for me to select an option. The problem is....the visual X interface never appears! Its just hidden!
I wrote directly to the X applications's STDOUT file description via /proc and then terminated the process which yielded the correct response in my waiting parent process. So it should be working but the X application just stays invisible for some reason.
I don't see why reading/writing to an external program via pipes is so....complicated. If anyone can tell me what I'm doing wrong it would be very helpful. I've read the man pages of the functions I'm using and still don't see what the problem is.
Notice the new lines close() for the pread and pwrite. Adding this makes it work! Commenting them out again makes it not work! I don't understand why this is necessary seeing as how the child (dmenu) only reads from stdin and writes to stdout. I get the EOF thing in the parent (not shown) but don't get why this additional change it needed.
If all file descriptors referring to the write end of a pipe have been closed, then an attempt to read(2) from the pipe will see end-of-file (read(2) will return 0). ... An application that uses pipe(2) and fork(2) should use suitable close(2) calls to close unnecessary duplicate file descriptors; this ensures that end-of-file and SIGPIPE/EPIPE are delivered when appropriate.
So you need close(pwrite) in the child else close(pwrite) in the parent has no effect.