ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Ah indeed EOF IS needed (and man page even mentions this too). I added and it didn't fix the problem. For *SOME* reason I had to close the parent only FDs in the child and magically it works!
Notice the new lines close() for the pread[0] and pwrite[1]. 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[1]) in the child else close(pwrite[1]) in the parent has no effect.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.