c - Server/Client comunication through pipe -
i started learning ipc , have issues. wrote program creates 2 processes communicate through pipe this:
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <unistd.h> int main(void) { int pfds[2]; char buf[30]; pipe(pfds); if (!fork()) { printf(" child: writing pipe\n"); write(pfds[1], "test", 5); printf(" child: exiting\n"); exit(0); } else { printf("parent: reading pipe\n"); read(pfds[0], buf, 5); printf("parent: read \"%s\"\n", buf); wait(null); } return 0; } sorry not handling potential errors, wrote simplicity.
this works great question is: there possibility have 2 programs - server/client(two separate executables - not parent process/child process relationship) communicate through pipe? can through fifos?
thank you!
a regular pipe can connect 2 related processes. created process , vanish when last process closes it.
to communicate between 2 separate processes must use named pipes (fifo).
Comments
Post a Comment