Renaming folders

This commit is contained in:
Fabio Scotto di Santolo
2024-09-11 10:47:59 +02:00
parent 67447f7370
commit 3c4b9bdc56
31 changed files with 0 additions and 0 deletions

39
chp3_process/ex12.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
void add_children(pid_t children[], pid_t pid);
int main(void)
{
pid_t parent_pid = getpid();
pid_t children[1024] = {-1};
for (int i = 0; i < 4; i++) {
pid_t pid = fork();
add_children(children, pid);
}
if (parent_pid = getpid()) {
wait(NULL);
printf("pids: ");
for (int i = 0; i < 1024; i++) {
if (children[i] == -1) {
printf("\n");
break;
}
printf("%d ", children[i]);
}
}
return 0;
}
void add_children(pid_t children[], pid_t pid)
{
for (int i = 0; i < 1024; i++) {
if (children[i] < 0) {
children[i] = pid;
break;
}
}
}