일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 5622
- Zero That Out
- 4949
- file IO
- 브런치
- 바샤
- 10773
- BAKA
- IT
- LJESNJAK
- The Balance of the World
- Parenthesis
- Baekjoon
- system programming
- QA
- c++
- Process Communication
- 백준
- c
- 시프
- 균형잡힌 세상
- File 조작
- 해바
- 입력 버퍼
- 2941
- 1874
- 시스템 프로그래밍
- 전자책
- process control
- For Beginners
- Today
- Total
목록System Programming (15)
해바
Socket() 시스템 호출을 이용하여 간단한 메시지를 교환하는 client/server 프로그램을 작성하라 : Domain은 PF_UNIX, socket type은 SOCK_DGRAM, 프로토콜은 0을 이용 교환할 간단한 메시지는 "This is a message from the client" 서버 프로그램은 하단의 serv.c에 나와 있음 Client 프로그램을 작성할 것 // serv.c #include #include #include #include #include #define NAME "socket" #define SIZE 1024 main() { int sock, length, fromlen; struct sockaddr_un name, from; char buf[SIZE] = ""; soc..
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 #include #i..
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(..