First of all, sorry if my English is not free and understandable.
I work on understanding pipes and communication between processes. I tried to implement two c-programs, one of which writes to a certain channel from what it reads from standard input, and the other waits until the pipe opens and reads it, and prints to standard output before EOF.
Here is the code for the writer pipe:
fd = open(filename, O_RDWR);
if(fd == -1) print_error();
while(fgets(buffer, BUFFER_SIZE, stdin) != NULL) {
if(write(fd, buffer, BUFFER_SIZE) == -1) print_error();
}
and here is the code for the reader channel:
while(1) {
if((fd = open(filename, O_RDWR)) == -1) {
if(errno == ENOENT) sleep(1);
else print_error();
}
else {
while(read(fd, buffer, BUFFER_SIZE) != 0) {
fprintf(stdout, "%s", buffer);
}
}
}
, , , - , , - . , EOF, CTRL + D , - , , , while (1) , syscall , EOF, : read(fd, buffer, BUFFER_SIZE) , .
, , , , ?