From f28cbd896e7a20151aab6265b86da5732343ec8f Mon Sep 17 00:00:00 2001 From: Sohyun Lee <sh119@ajou.ac.kr> Date: Tue, 25 Jan 2022 16:32:31 +0900 Subject: [PATCH] lec13 --- lec13/forktest.c | 17 +++++++++++++++++ lec13/lserr.txt | 1 + lec13/lsout.txt | 1 + lec13/lsoutierr.txt | 2 ++ lec13/output.txt | 1 + lec13/test.c | 7 +++++++ lec13/thread2.c | 37 +++++++++++++++++++++++++++++++++++++ lec13/threadtest.c | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 101 insertions(+) create mode 100644 lec13/forktest.c create mode 100644 lec13/lserr.txt create mode 100644 lec13/lsout.txt create mode 100644 lec13/lsoutierr.txt create mode 100644 lec13/output.txt create mode 100644 lec13/test.c create mode 100644 lec13/thread2.c create mode 100644 lec13/threadtest.c diff --git a/lec13/forktest.c b/lec13/forktest.c new file mode 100644 index 0000000..91dc9b6 --- /dev/null +++ b/lec13/forktest.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +int main() +{ + int a = 0; + pid_t pid ,pid2; + pid = fork(); + pid2 = fork(); + for (int i = 0; i < 100; i++) + { + sleep(1); + if(pid == 0) + printf("PID %d : PID2 %d : A=%d : i=%d : \n", pid,pid2, a++, i); + } +} diff --git a/lec13/lserr.txt b/lec13/lserr.txt new file mode 100644 index 0000000..06488f2 --- /dev/null +++ b/lec13/lserr.txt @@ -0,0 +1 @@ +ls: cannot access 'zzz': No such file or directory diff --git a/lec13/lsout.txt b/lec13/lsout.txt new file mode 100644 index 0000000..9843a01 --- /dev/null +++ b/lec13/lsout.txt @@ -0,0 +1 @@ +-rw-r--r-- 1 pcc022 pcc 104 1월 25 15:19 test.c diff --git a/lec13/lsoutierr.txt b/lec13/lsoutierr.txt new file mode 100644 index 0000000..1cd2a91 --- /dev/null +++ b/lec13/lsoutierr.txt @@ -0,0 +1,2 @@ +ls: cannot access 'zzz': No such file or directory +-rw-r--r-- 1 pcc022 pcc 104 1월 25 15:19 test.c diff --git a/lec13/output.txt b/lec13/output.txt new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/lec13/output.txt @@ -0,0 +1 @@ +Hello diff --git a/lec13/test.c b/lec13/test.c new file mode 100644 index 0000000..f5243a2 --- /dev/null +++ b/lec13/test.c @@ -0,0 +1,7 @@ +#include <stdio.h> +#include <stdlib.h> + +int main() +{ + printf("System Call : %d\n", system("ls -li")); +} diff --git a/lec13/thread2.c b/lec13/thread2.c new file mode 100644 index 0000000..d9761b6 --- /dev/null +++ b/lec13/thread2.c @@ -0,0 +1,37 @@ +#include <pthread.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + + +int bbb = 0; + +void fn_s() +{ + static int a = 0; + printf("== %d %d ==",a++, bbb++); +} + + +void *run (void *arg) +{ + printf("Hello world of POSXI threads.%d\n", (int) pthread_self() ); + for (int i = 0; i < 100; i++) + { + usleep(100); + fn_s(); + } + return 0; + +} + +int main() +{ + pthread_t thread1; + int result1; + pthread_create(&thread1, NULL, run, NULL ); + run((void *) 0); + pthread_join(thread1, (void **) &result1); + printf("Thread return %d at the end\n", result1); +} + diff --git a/lec13/threadtest.c b/lec13/threadtest.c new file mode 100644 index 0000000..5264c6e --- /dev/null +++ b/lec13/threadtest.c @@ -0,0 +1,35 @@ +#include <pthread.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +int bbb = 0; +void fn_s() +{ + static int a = 0; + printf("== %d %d ==",a++, bbb++); +} + + +void *run (void *arg) +{ + printf("Hello world of POSXI threads.%d\n", (int) pthread_self() ); + for (int i = 0; i < 100; i++) + { + usleep(10000); + fn_s(); + } + return 0; + +} + + +int main() +{ + pthread_t thread1; + int result1; + pthread_create(&thread1, NULL, run, NULL ); + pthread_join(thread1,(void **) &result1); + printf("Thread return %d at the end\n", result1); +} + -- GitLab