Skip to content
Snippets Groups Projects
Commit 082a48fe authored by Nayoung Kim's avatar Nayoung Kim
Browse files

lec14

parent b794a74d
No related branches found
No related tags found
No related merge requests found
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
#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);
}
}
ls: cannot access 'zzz': No such file or directory
-rw-r--r-- 1 pcc004 pcc 127 1월 25 15:22 test.c
ls: cannot access 'zzz': No such file or directory
-rw-r--r-- 1 pcc004 pcc 127 1월 25 15:22 test.c
hello
#include <stdio.h>
#include <stdlib.h>
int main(){
printf("System Call: %d\n", system("ls -li test.c zzz"));
return(100);
}
#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);
}
#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);
}
#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);
}
#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);
}
#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);
}
#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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment