logo

Crowdly

Dado el siguiente código C, ¿cuántos semáforos serían necesarios para garantizar...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Dado el siguiente código C, ¿cuántos semáforos serían necesarios para garantizar que se impriman siempre los números en orden?

#include <fcntl.h>

#include <semaphore.h>

#include <stdio.h>

#include <stdlib.h>

#include <sys/stat.h>

#include <sys/wait.h>

#include <unistd.h>

int main(void) {

pid_t pid;

pid = fork();

if (pid < 0) {

perror("fork");

exit(EXIT_FAILURE);

}

if (pid == 0) {

printf("1\n");

printf("3\n");

} else {

printf("2\n");

printf("4\n");

wait(NULL);

exit(EXIT_SUCCESS);

}

}

0%
0%
100%
0%
More questions like this

Want instant access to all verified answers on moodle.uam.es?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!