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
- BAKA
- c++
- 시프
- process control
- 백준
- For Beginners
- Baekjoon
- LJESNJAK
- QA
- system programming
- 5622
- 10773
- Parenthesis
- Zero That Out
- 바샤
- The Balance of the World
- 해바
- 입력 버퍼
- file IO
- 4949
- 1874
- 균형잡힌 세상
- File 조작
- IT
- 브런치
- Process Communication
- c
- 2941
- 시스템 프로그래밍
- 전자책
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