More Pipes
-
FILE *popen(const char *command, const char *type);
- This is a shortcut for communicating with another process.
- This will
- Set up a pipe
- if type is "r" the current process is on the read end of the pipe.
- If type is "w" the current process is on the write end.
- I know that type is a
const char *
but this is c for string.
- Fork
- exec command
- And return a c style file stream (FILE *) , or NULL if something fails.
- The process can then read or write from/to the stream.
-
int pclose(FILE *stream);
- Close the pipe
- Wait for the child to exit.
- Return the exit status.
- or -1 on error.
- There are more details, but these will do for now.
- Look at popenRead.cpp and popenWrite.cpp.
-
int mkfifo(const char *pathname, mode_t mode);
- The arguments are much like open.
- This builds the file on the system which is an interface to a pipe.
- This overcomes the problem that the pipe must be shared between two related processes.
- We have already worked with these.
- Open will block for read only or write only until the other end is opened.
- Look at dieServer.cpp and dieClient.cpp
-
int unlink(const char *pathname);
- removes the file.
- But only if this is the last link to the file.
- And no processes have the file open.
- The file will be removed after these exit.