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

185
Visualizações
How could I simulate a lack of file descriptor?

I would like to provoke a situation where there is no file descriptor remaining.

I have been thinking about 2 possibilities:

  1. Opening thousands of files randomly until the result of open is -1
  2. Set a very low number of file descriptor available (let's say stdin, stdout and stderr).

How would you do it?

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

0

You can limit the number of file descriptors a process can open under Linux using ulimit.

Executing ulimit -n 3 before running your C program should make it an error to open any more files, since stdin, stdout, and stderr take up the first 3 descriptors.

An example:

$ ulimit -n 3
$ echo > /dev/null
zsh: too many open files: /dev/null

The shell process itself attempts to open /dev/null to redirect stdout before closing it there, therefore it gets an error. Your C program will be fed the exact same error the first time it calls fopen, open, socket, etc (or anything that allocates a new file descriptor).

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