MC504 Sistemas Operacionais
Prof. Dr. Eng. Isaías Bittencourt Felzmann
isaias@ic.unicamp.br
Campinas, 2s/2026
Processos
1/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Aviso Legal
The following set of slides are copyright Silberschatz, Galvin and Gagne, 2018. Modifications were made for their use in conjunction with MC504. The original material is available at os-book.com .
Os direitos autorais do conjunto de slides a seguir pertencem a Silberschatz, Galvin and Gagne, 2018. Foram feitas modificações para seu uso em MC504. O material original está disponível em os-book.com .
Este material foi elaborado com apoio de ferramentas de IA generativa como recurso auxiliar. O conteúdo foi revisado, validado e é de responsabilidade do docente.
2/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Resumo
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
3/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Objetivos
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
4/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Conceito de Processo
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
5/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Conceito de Processo (cont.)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
6/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Processo na Memória
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
7/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Layout de Memória de um Programa C
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
8/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Estado do Processo
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
9/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Diagrama do Estado do Processo
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
10/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bloco de Controle de Processo (PCB)
Informações associadas a cada processo (também chamado de bloco de controle de tarefas)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
11/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Threads
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
12/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Representação de Processos no Linux
Representado pela estrutura C task_struct
�pid_t pid; /* identificador de processo */ �long state; /* estado do processo */ �unsigned int time_slice /* informações de escalonamento */ �struct task_struct *parent;/* pai deste processo */ �struct list_head children; /* filhos deste processo */ �struct files_struct *files;/* lista de arquivos abertos */ �struct mm_struct *mm; /* espaço de endereçamento deste processo */
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
13/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Escalonamento de Processos
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
14/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Filas de Prontos e Espera
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
15/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Representação do Escalonamento
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
16/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Troca de CPU entre Processos
Uma troca de contexto ocorre quando a CPU alterna de um processo para outro.
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
17/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Troca de Contexto
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
18/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Operações sobre Processos
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
19/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Criação de Processos
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
20/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Criação de Processos (Continuação)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
21/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Uma Árvore de Processos no Linux
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
22/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Criação de Processo em C com fork()
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
23/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Criando um Processo com a API do Windows
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
24/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Término de Processo
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
25/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Término de Processo
pid = wait(&status);
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
26/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Comunicação entre processos
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
27/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Modelos de Comunicação
(a) Memória compartilhada. (b) Mensageria
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
28/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Problema Produtor-Consumidor
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
29/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
IPC – Memória Compartilhada
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
30/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bounded-Buffer – Memória Compartilhada
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
31/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Produtor – Memória Compartilhada
item next_produced; �
while (true) {
/* produz um item em next_produced */
while (((in + 1) % BUFFER_SIZE) == out)
; /* não faz nada */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
32/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Processo Consumidor
item next_consumed; �
while (true) {� while (in == out)
; /* não faz nada */� next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;�
/* consome o item em next_consumed */
}
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
33/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Como preencher todos os buffers?
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
34/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Produtor
while (true) {� /* produz um item em next_produced */
while (counter == BUFFER_SIZE)
; /* não faz nada */
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
counter++;
}
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
35/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Consumidor
while (true) {
while (counter == 0)
; /* não faz nada */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
counter--;
/* consome o item em next_consumed */
}
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
36/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Condições da Corrida
S0: produtor executa register1 = counter {register1 = 5}�S1: produtor executa register1 = register1 + 1 {register1 = 6} �S2: consumidor executa register2 = counter {register2 = 5} �S3: consumidor executa register2 = register2 – 1 {register2 = 4} �S4: produtor executa counter = register1 {counter = 6} �S5: consumidor executa counter = register2 {counter = 4}
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
37/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Condição da Corrida (Continuação)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
38/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
IPC – Mensageria
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
39/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Mensageria (continuação)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
40/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Implementação do Enlace de Comunicação
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
41/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Comunicação Direta
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
42/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Comunicação Indireta
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
43/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Comunicação indireta (continuação)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
44/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Comunicação indireta (continuação)
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
45/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Sincronização
A mensageria pode ser bloqueante ou não bloqueante
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
46/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Produtor-Consumidor: Mensageria
message next_produced;� while (true) {� /* produz um item em next_produced */�
send(next_produced);
}
message next_consumed;� while (true) {� receive(next_consumed)�� /* consome o item em next_consumed */� }
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
47/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Buffering
1. Capacidade zero – nenhuma mensagem é enfileirada em um enlace.�O remetente deve esperar pelo receptor (ponto de encontro)
2. Capacidade limitada – comprimento finito de n mensagens�O remetente deve esperar se o link estiver cheio
3. Capacidade ilimitada – comprimento infinito �O remetente nunca espera
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
48/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Exemplos de Sistemas IPC - POSIX
ftruncate(shm_fd, 4096);
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
49/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Produtor IPC POSIX
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
50/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
IPC POSIX Consumidor
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
51/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Pipes
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
52/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Pipes Comuns
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
53/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Pipes Nomeados
Silberschatz, Galvin e Gagne ©2018
Operating System Concepts– 10th Edition
54/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais
Bibliografia
Capítulo 2.
Capítulo 3.
55/55
rev. 2s/2026
IC/UNICAMP – MC504 Sistemas Operacionais