diff --git a/lec12/Makefile.2 b/lec12/Makefile.2 new file mode 100644 index 0000000000000000000000000000000000000000..9dbc9c09dc0845adea23244859e4ce1da717d171 --- /dev/null +++ b/lec12/Makefile.2 @@ -0,0 +1,8 @@ +main: main.o fx_s15_16.o + cc main.o fx_s15_16.o -o main +main.o: main.c fx_head.h fx_s15_16.h + cc -c main.c +fx_s15_16.o: fx_head.h fx_s15_16.c + cc -c fx_s15_16.c +clean: + rm main *.o *.out diff --git a/lec13/forktest.c b/lec13/forktest.c new file mode 100644 index 0000000000000000000000000000000000000000..9223066460396a0f3130b96f59011ea407ed39b3 --- /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..f386eaf77adf57771d2d03c9f780a200d19089b2 --- /dev/null +++ b/lec13/lsout.txt @@ -0,0 +1 @@ +-rw-r--r-- 1 pcc004 pcc 127 1월 25 15:22 test.c diff --git a/lec13/lsoutierr.txt b/lec13/lsoutierr.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec19ad56b920e55c7dc435c505eeb0a064f13000 --- /dev/null +++ b/lec13/lsoutierr.txt @@ -0,0 +1,2 @@ +ls: cannot access 'zzz': No such file or directory +-rw-r--r-- 1 pcc004 pcc 127 1월 25 15:22 test.c diff --git a/lec13/output.txt b/lec13/output.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce013625030ba8dba906f756967f9e9ca394464a --- /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..f0c7b0e10592ffa96216a604e717fa277240a5e9 --- /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 test.c zzz")); + return(100); +} diff --git a/lec13/th3.c b/lec13/th3.c new file mode 100644 index 0000000000000000000000000000000000000000..c47f256b9fdebb3951b43e3f705da53f76ea7b96 --- /dev/null +++ b/lec13/th3.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +int bbb = 0; +void fn_s() +{ + char bufff[10]; + static int a = 0; + setvbuf(stdout, bufff, _IOFBF, 10); + printf("== %d %d ==",a++, bbb++); +} + +void *run (void *arg) +{ + printf("Hello world of POSIX threads.%d\n", (int) (0) ); + for (int i = 0; i < 10; i++) + { + sleep(1); + fn_s(); + } + return 0; +} + +int main() +{ + int result1; + run((void *) 0); + printf("Thread return %d at the end\n", result1); +} 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..3e8026c5a281035ca6bbe5bb05c71173c52c0042 --- /dev/null +++ b/lec13/threadtest.c @@ -0,0 +1,42 @@ +#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++) + { + sleep(1); + fn_s(); + } + return 0; + +} + +int main() +{ + pthread_t thread1; + // pthread_t thread2; + // pthread_t thread3; + int result1; + // int result2; + pthread_create(&thread1, NULL, run, NULL ); + // pthread_create(&thread2, NULL, run, NULL ); + // pthread_create(&thread3, NULL, run, NULL ); + pthread_join(thread1, &result1); + // pthread_join(thread2, &result2); + printf("Thread return %d at the end\n", result1); + // printf("Thread return %d at the end\n", result2); +} + diff --git a/lec14/prtest.c b/lec14/prtest.c new file mode 100644 index 0000000000000000000000000000000000000000..9188cf938b534479682fdc72c0633cc0538ff6b8 --- /dev/null +++ b/lec14/prtest.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main() +{ + char a; + short b; + int c; + long long d; + + scanf("%d %d %d %d", &a, &b, &c, &d); + printf("%d %d %d %d\n", a, b, c, d); +} diff --git a/lec14/th4.c b/lec14/th4.c new file mode 100644 index 0000000000000000000000000000000000000000..6f3fa9c3f787f889f6eb31d50228e128b4fd409c --- /dev/null +++ b/lec14/th4.c @@ -0,0 +1,34 @@ +#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++); + fflush(stdout); +} + + +void *run (void *arg) +{ + printf("Hello world of POSIX threads.%d\n", (int) (0) ); + for (int i = 0; i < 10; i++) + { + sleep(1); + fn_s(); + } + return 0; + +} + +int main() +{ + int result1; + char bufff[10]; + setvbuf(stdout,bufff, _IONBF, 10); + run((void *) 0); + printf("Thread return %d at the end\n", result1); +} diff --git a/lec14/threadtest.c b/lec14/threadtest.c new file mode 100644 index 0000000000000000000000000000000000000000..4308c85ac70f4c45168af5e3618237a3b59f20d5 --- /dev/null +++ b/lec14/threadtest.c @@ -0,0 +1,48 @@ +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <stdlib.h> +#include <pthread.h> + +int bbb = 0; + +void fn_s() +{ + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static int a = 0; + printf("<= %d %d =>",a, bbb); + pthread_mutex_lock(&mutex); + a++; bbb++; + pthread_mutex_unlock(&mutex); +} + + +void *run (void *arg) +{ + printf("Hello world of POSXI threads.%d\n", (int) pthread_self() ); + for (int i = 0; i < 1000000; i++) + { + //usleep(10000); + fn_s(); + } + return 0; + +} + +int main() +{ + pthread_t thread1; + pthread_t thread2; + pthread_t thread3; + int result1, result2, result3; + + pthread_create(&thread1, NULL, run, NULL ); + pthread_create(&thread2, NULL, run, NULL ); + pthread_create(&thread3, NULL, run, NULL ); + run((void *) 0); + pthread_join(thread1, (void **) &result1); + pthread_join(thread2, (void **) &result2); + pthread_join(thread3, (void **) &result3); + printf("\nThread return %d at the end\n", result1); +} +