
Answer-first summary for fast verification
Answer: 8 e 8.
## Explanation This question tests understanding of the `fork()` system call in C programming and process creation. ### Analysis of the code: 1. The program starts with **1 process** (the main process). 2. The `for` loop runs 3 times, each time calling `fork()`: - **First fork()**: Creates 1 child process → Total processes: 2 - **Second fork()**: Both existing processes (parent and child) fork → Creates 2 more processes → Total processes: 4 - **Third fork()**: All 4 existing processes fork → Creates 4 more processes → Total processes: 8 ### Key points: - Each `fork()` creates a child process that is an exact copy of the parent. - After each fork, both parent and child continue execution from the next instruction. - The loop runs 3 times, so we have 2³ = 8 processes total. - The program doesn't create any explicit threads (no `pthread_create()` or similar), so threads = 0. ### Why option E (8 e 8) is incorrect: 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: - A) 1 e 0 → Incorrect (more than 1 process) - B) 3 e 0 → Incorrect (more than 3 processes) - C) 4 e 1 → Incorrect (more than 4 processes, 0 threads) - D) 7 e 7 → Incorrect (8 processes, 0 threads) - E) 8 e 8 → Incorrect (8 processes, but 0 threads, not 8) 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.
Author: Danyel Barboza
Ultimate access to all questions.
No comments yet.
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.