Error: ‘O_CREATE’ undeclared (first use in this function)
c, linux, producer-consumer, signals
Solution
The macro name should be `O_CREAT`, not `O_CREATE`.
And yes, I hate these names in Unix world, too.
From Wikipedia
Ken Thompson was once asked what he would do differently if he were redesigning the UNIX system. His reply: "I'd spell `creat` with an `e`."
Problem
The following code is supposed to synchronize two processes, a producer that writes some integers, and a consumers that reads them, now when executing it gives me this error: ``` ‘O_CREATE’ undeclared (first use in this function) ``` But I have included the `fcntl.h`, what else might be the problem? ``` int main(void) { int fd, n, i; pid_t pid, ppid; char buf[1]; if((fd=open("/tmp/data_file", O_APPEND|O_CREATE, 0640)) <0) exit(1); sigset(SIGTERM,SIG_IGN);/* signal */ ; sigset(SIGINT,SIG_IGN); /* signal */ pid=fork(); switch (pid) { case -1: { perror(“FORK”); exit(1); } case 0: /* child process - Producer */ sigset(SIGUSR1,wakeup); sighold(SIGUSR1); /* block / hold signals SIGUSR1 until sigpause*/ for (i=0; i<=100; i++) { /* sleep a random amount of time */ n = (int)(getpid()%256); srand((unsigned)n); sleep(rand() %5); /* writes a character in file */ sprintf(buf,"%d",i); write(fd, buf,sizeof(buf)); fprintf(stderr,"Producer PID=%d value = %d\n",getpid(), i); ppid=getppid(); kill(ppid, SIGUSR2); sigpause(SIGUSR1); /* pause(); until SIGUSR! received*/ } break; default: /* -parent code - Consumer */ sigset(SIGUSR2,wakeup); sighold(SIGUSR2); /* block / hold signals SIGUSR2 until sigpause*/ for (i=0; i<=100; i++) { /* sleep a random amount of time */ n = (int)(getpid()%256); srand((unsigned)n); sleep(rand() %5); sigpause(SIGUSR2); /* pause(); */ /* reads a character from file */ read(fd, buf,sizeof(buf)); fprintf(stderr,"Consumer PID=%d value=%d\n",getpid(),atoi(buf)); kill(pid, SIGUSR1) ; } break; } exit(0); } ```