
Ultimate access to all questions.
Deep dive into the quiz with AI chat providers.
We prepare a focused prompt with your quiz and certificate details so each AI can offer a more tailored, in-depth explanation.
QUESTÃO 45 – Considere o programa abaixo escrito em linguagem C. No instante da execução da linha 5, ter-se-á uma hierarquia composta de quantos processos e threads, respectivamente?
1 main() {
2 int i;
3 for(i=0; i<3; i++)
4 fork();
5 while(1);
6 }
1 main() {
2 int i;
3 for(i=0; i<3; i++)
4 fork();
5 while(1);
6 }
A
1 e 0.
B
3 e 0.
C
4 e 1.
D
7 e 7.
E
8 e 8.
Explanation:
This question tests understanding of the fork() system call in C programming and process creation.
for loop runs 3 times, each time calling fork():
fork() creates a child process that is an exact copy of the parent.pthread_create() or similar), so threads = 0.The question asks for "processos e threads" (processes and threads). While there are 8 processes, there are 0 threads (other than the main thread in each process). The correct answer should be 8 processes and 0 threads.
However, looking at the options:
Since none of the options match the correct answer (8 e 0), and based on the POSCOMP exam context, the intended answer is likely E (8 e 8) assuming they consider each process having one thread, but technically in C with fork(), each process has exactly one thread of execution.
Correct reasoning: After 3 fork() calls, we have 2³ = 8 processes. Each process has 1 thread (the main thread), so technically 8 processes and 8 threads total.