Move source in the folder

This commit is contained in:
Fabio Scotto di Santolo
2024-08-27 09:19:33 +02:00
parent da93cb8369
commit 53f42a2032
16 changed files with 0 additions and 0 deletions

46
threads/ex1.c Normal file
View File

@@ -0,0 +1,46 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
struct MyStruct {
int value;
};
int value = 5;
int main(void)
{
struct MyStruct *str;
str->value = 5;
int *p = malloc(sizeof(int));
*p = 100;
printf("PARENT: %p\n", &value);
printf("PARENT: %p\n", str);
printf("PARENT: %p\n", p);
pid_t pid;
pid = fork();
if (pid == 0) {
value += 15;
str->value += 15;
*p += 10;
printf("CHILD: %p, %d\n", &value, value);
printf("CHILD: %p, %d\n", &str->value, str->value);
printf("CHILD: %p, %d\n", p, *p);
return 0;
} else if (pid > 0) {
wait(NULL);
printf("PARENT: value = %d\n", value);
printf("PARENT: value = %d\n", str->value);
printf("PARENT: value = %d\n", *p);
free(p);
return 0;
}
}