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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.