diff --git a/lec13/forktest.c b/lec13/forktest.c new file mode 100644 index 0000000000000000000000000000000000000000..91dc9b6a292764264358501efd5f93a4d9d22f06 --- /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 0000000000000000000000000000000000000000..06488f2516e233b2d10218765d8ae6ba476cf386 --- /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 0000000000000000000000000000000000000000..9843a016b828ffd334923cb168ab3449651f96d1 --- /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 0000000000000000000000000000000000000000..1cd2a912af8c49ac61f697cbab392c5970064af3 --- /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 0000000000000000000000000000000000000000..e965047ad7c57865823c7d992b1d046ea66edf78 --- /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 0000000000000000000000000000000000000000..f5243a2ce97907e42bafc91a5b791750e6f159cb --- /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 0000000000000000000000000000000000000000..d9761b6b6e81e4ddecb5d22f958efd084132da59 --- /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 0000000000000000000000000000000000000000..5264c6e5ecbf228c6499297518ba06f8003d223e --- /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); +} +