fifo생성하는 코드인데, cygwin에뮬에서는 왜 멈출까요?
글쓴이: mtlc / 작성시간: 화, 2004/10/05 - 5:26오후
컴파일 에러는 없는데, 실행시키면 fifo는 생성이 되는데 아무런출력이 안되고 멈춰버리네요.
[parent] Hello, world <- 이게 5번찍혀야 정상인데... 왜 멈추죠?
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
void writer(const char* msg, int count, int fd) {
for( int i = 0 ; i < count; i++) {
write(fd,msg,strlen(msg));
sleep(1);
}
}
void reader(int fd) {
char buffer[1024];
ssize_t n;
while ( (n = read(fd, buffer, 1024)) > 0)
write(STDOUT_FILENO, buffer, n);
}
int main() {
pid_t pid;
int readfd, writefd;
if ((mkfifo("/tmp/ksh.1", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) && (errno != EEXIST)) {
printf("can't create %s\n", "/tmp/ksh.1");
}
pid = fork();
if ( pid == (pid_t) 0) {
readfd = open("/tmp/ksh.1", O_RDONLY, 0);
reader(readfd);
close(readfd);
}
else {
writefd = open("/tmp/ksh.1", O_WRONLY, 0);
writer("[parent] Hello, world.", 5, writefd);
close(writefd);
}
return 0;
}Forums:


댓글 달기