Skip to content
Snippets Groups Projects
Commit f28cbd89 authored by 이소현's avatar 이소현
Browse files

lec13

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