Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Parenthesis
- For Beginners
- 브런치
- Baekjoon
- QA
- system programming
- 1874
- file IO
- 해바
- 시프
- File 조작
- BAKA
- c++
- 시스템 프로그래밍
- IT
- 2941
- process control
- The Balance of the World
- 입력 버퍼
- 균형잡힌 세상
- c
- 전자책
- LJESNJAK
- 백준
- 4949
- 10773
- Process Communication
- 5622
- Zero That Out
- 바샤
Archives
- Today
- Total
해바
Lab #14 본문
FIFO를 이용하여 다음과 같은 프로그램을 작성하라.
- Fifo-serv 프로그램에서는 "myfifo"라는 이름의 FIFO를 생성한다.
- Fifo-clnt 프로그램에서는 stdin으로부터 한번에 최대 1024byte 크기의 데이터를 읽어들인 후, 데이터를 "myfifo"에 쓴다.
- Fifo-serv 에서 "myfifo"에 쓰여진 데이터를 읽어서 stdout에 출력한다.
- mkfifo, open, close, read, write 등의 system call을 사용하면 작성할 수 있다.
- 테스트 입력으로 다음을 사용한다 :
This is junior-level
System Programming course
Fall semester of year 2019
// Fifo-serv.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define BUFSIZE 1024
int main() {
int fd;
char buf[BUFSIZE];
char* myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666);
while (1) {
if((fd = open(myfifo, O_RDONLY)) == -1) perror("open");
memset(buf, '\0', BUFSIZE);
read(fd, buf, BUFSIZE);
write(STDOUT_FILENO, buf, strlen(buf));
close(fd);
}
return 0;
}
// Fifo-clnt.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define BUFSIZE 1024
int main() {
int fd;
char buf[BUFSIZE];
char* myfifo = "/tmp/myfifo";
mkfifo(myfifo, 0666);
while(1) {
if((fd = open(myfifo, O_WRONLY)) == -1) perror("open");
fgets(buf, BUFSIZE, stdin);
write(fd, buf, strlen(buf));
close(fd);
}
return 0;
}
컴파일 :
%gcc Fifo-serv.c -o serv
%gcc Fifo-clnt.c -o clnt
실행 :
Terminal 1
%./serv
Terminal 2
%./clnt
client에서 입력 테스트 실행
정상출력 확인 후 종료(ex. Ctrl + C)
Comments