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
- process control
- LJESNJAK
- QA
- 1874
- 2941
- File 조작
- Baekjoon
- Zero That Out
- 입력 버퍼
- 브런치
- 균형잡힌 세상
- 백준
- 시스템 프로그래밍
- 시프
- system programming
- 10773
- For Beginners
- c
- file IO
- 4949
- 해바
- Process Communication
- BAKA
- 5622
- 전자책
- Parenthesis
- IT
- 바샤
- c++
- The Balance of the World
Archives
- Today
- Total
해바
Lab #13 본문
popen()과 pclose를 사용하여 "who | sort"를 실행 시킬 수 있는 프로그램을 작성하라.
// pipe.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
int main() {
FILE* read_fp, *write_fp;
char buf[BUFSIZ];
read_fp = popen("who", "r");
write_fp = popen("sort", "w");
if(read_fp != NULL && write_fp != NULL) {
fread(buf, sizeof(char), BUFSIZ, read_fp);
fwrite(buf, sizeof(char), strlen(buf), write_fp);
pclose(read_fp);
pclose(write_fp);
exit(0);
}
exit(1);
}
컴파일 :
%gcc pipe.c
실행 :
%./a.out
Comments