일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- IT
- 균형잡힌 세상
- LJESNJAK
- 4949
- 브런치
- Baekjoon
- 시프
- 시스템 프로그래밍
- QA
- 해바
- process control
- File 조작
- The Balance of the World
- 5622
- 바샤
- c
- 10773
- 백준
- 입력 버퍼
- c++
- For Beginners
- Process Communication
- system programming
- 2941
- file IO
- 전자책
- BAKA
- Zero That Out
- 1874
- Parenthesis
- Today
- Total
목록전체 글 (52)
해바
popen()과 pclose를 사용하여 "who | sort"를 실행 시킬 수 있는 프로그램을 작성하라. // pipe.c #include #include #include #include #include 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..
pipe(), fork(), execlp(), system call 들을 사용하여 "ps -ef | grep telnet"의 동작을 구현한다. 부모 프로세스는 파이프를 통해서 "ps -ef" 명령 결과를 출력한다. 자식 프로세스는 부모 프로세스가 출력한 결과를 받아 "grep telnet" 명령을 수행한다. #include #include #include #include int main() { int fd[2]; pid_t pid; if(pipe(fd) != 0) perror("pipe"); if((pid = fork()) == -1) perror("fork"); else if(pid == 0) { close(fd[1]); if(fd[0] != 0) { dup2(fd[0], 0); close(fd[0])..
두 개의 프로그램 parent.c(실행 파일 이름은 parent)와 child.c(child)를 다음과 같이 작성한다 : parent에서는 자식 프로세스(child)를 fork()와 exec() 시스템 호출을 이용하여 시작한다. parent에서 "parent: child initiated"라고 출력한다. child에서는 30sec 동안 sleep() 한다. 30sec가 되기 전에 parent에서 자식 프로세스에게 kill()을 사용하여 SIGTERM을 보낸다. child가 terminate 된 후 parent에서 다음과 같이 출력한다 : "Parent: child terminated" // parent.c #include #include #include #include int main() { pid_t ..
lab #9의 프로그램을 수정하여 다음의 프로그램을 작성하라 : 부모 프로세스는 자식 프로세스들의 종료를 기다리면서 종료하는 각 프로세스를 식별하여 메시지("Parent: First(또는 Second) Child: ")와 함께 종료 상태(status)를 출력하는 프로그램을 작성하라. // status.c #include #include #include #include int main() { int i = 0, status; pid_t pids[2]; while(pids[i] = fork()) { if(i + 1 == 2) break; ++i; } switch (pids[i]) { case -1: perror("fork"); case 0: switch (i) { case 0: execl("/bin/echo..
fork()와 wait()를 이용하여 다음의 프로그램을 작성하라 : 부모 프로세스는 두 개의 자식 프로세스를 생성한다 : Child 1, Child 2 각각의 자식 프로세스는 execl()을 이용하여 "echo" 커맨드를 실행하면서 "This is Child 1(또는 Child 2)"를 출력한다. 부모 프로세스는 wait() 를 실행하며 자식 프로세스들이 끝나기를 기다린다. wait()를 실행하기 전 "Parent: Waiting for children"하고 출력한다. 자식 프로세스들이 끝나면 부모는 "Parent: All Children terminated"하고 출력한다. // wait.c #include #include #include #include int main() { int i = 0, sta..
부모 프로세스는 sample.txt에 있는 문자열의 길이 만큼 자식 프로세스들을 생성한 후, waitpid 를 사용하여 생성된 순서대로 거두어 들이는 프로그램을 작성하라. 이 때 자식 프로세스는 자신의 순서만큼 문자열을 복사해서 output.txt에 작성하고 종료해야 한다. 결과 예시 sample.txt 내용 system // waitpid.c #include #include #include #include #include #include #include #include int main() { int ofd, nfd, status, len, i = 0; char buf[BUFSIZ]; pid_t* pids; if((ofd = open("sample.txt", O_RDONLY)) == -1) perror(..
시스템 호출 getenv, setenv 등을 사용하여 환경 변수 PATH의 현재 값을 지우고 Lab #7이 저장된 directory 값으로 변경하는 프로그램을 작성하라. // env.c #include #include #include #include #include int main(int argc, char* argv[]) { char* path, *cwd; if(argc != 2) { printf("usage: a.out \n"); exit(1); } if((path = getenv(argv[1])) == NULL) { printf("File does not exist.\n"); exit(1); } printf("BEFORE ENV : %s\n", path); cwd = getcwd(NULL, BUFS..

다음과 같은 프로그램을 작성하라 : 인자로서 디렉토리 이름과 파일의 접미사(suffix)를 읽어 들인다. 주어진 디렉토리를 탐색하여 이름에 인자로 주어진 접미사가 포함된 첫번째 파일을 찾아 그 파일의 i-node 값과 파일 이름을 출력한다. 주어진 파일이름(*s1)이 접미사 (*s2)를 포함하는지 check 해 주는 함수 int match(char* s1, char* s2)를 활용할 것 int match(char* s1, char* s2) { int diff = strlen(s1) - strlen(s2); if(strlen(s1) > strlen(s2)) return (strcmp(&s1[diff], s2) == 0); else return 0; } #include #include #include #in..