Trouble with named pipe...
Good evening,
I am trying to use a named pipe to implement communication between two UNIX commands. It does not compile properly. The error message in Dev-C++ is "syntax error before numeric constant". What am I missing?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
int main(int argc, char *argv[]){
pid_t pid;
int fd[2];
int val;
int mkfifo(const char *myFifo, 0644); /* create a named pipe */
pid = fork(); /* fork */
if(pid < 0){
printf("Cannot fork");
exit(1);
}
if(pid > 0){
/* parent process */
dup2(fd[1], 1);
close(fd[0]);
execlp("ps", "ps", "-ef", (char *)0);
}
else if(pid == 0){
/* child process */
dup2(fd[0], 0);
close(fd[1]);
execlp("grep", "grep", "ct321j", (char *)0);
}
}
Thanks!
Damien