Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
What is the lifetime of shared memory on Linux

I am creating, writing to and reading from a shared segment on Linux using the ftok/shmget/shmat/shmdt functions.

If I write to the segment in one program which then exits, and subsequently read the segment from another program later, I am surprised to find the data still there.

I would have expected that when the last process sharing a segment does a shmdt, the segment would be free'd.

Can I rely on this behavior? Or is it analogous to continuing to use a pointer after free()'ing it?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The shared memory area remains until it is deleted via shmctl(shmid,IPC_RMID,...) [or system reboot]. This will take effect after every process has done shmdt [or terminated].

The semantics are very similar to a file. shmat is like open. shmdt is like close and the [above] shmctl is like unlink.

If you close a file, you'd like it to persist until specifically deleted, wouldn't you? So, shared memory segments operate similarly

over 4 years ago · Santiago Trujillo Relatório

0

shmdt only detaches you memory, no erase/overwrite is performed on the data segment. Until some other process maps and uses it again data will persevere.

Also, you should use newer, POSIX compliant mmap.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda