Modify PID Manager with threads

This commit is contained in:
Fabio Scotto di Santolo
2024-08-28 18:18:10 +02:00
parent c5002973e6
commit b941fca02a
4 changed files with 103 additions and 1 deletions

31
threads/ex417.c Normal file
View File

@@ -0,0 +1,31 @@
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int value = 0;
void *runner(void *param);
int main(int argc, char *argv[]) {
pid_t pid;
pthread_t tid;
pthread_attr_t attr;
pid = fork();
if (pid == 0) {
pthread_attr_init(&attr);
pthread_create(&tid, &attr, runner, NULL);
pthread_join(tid, NULL);
printf("CHILD: value = %d\n", value);
} else if (pid > 0) {
wait(NULL);
printf("PARENT: value = %d\n", value);
}
}
void *runner(void *param) {
value = 5;
pthread_exit(0);
}