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

239
Visualizações
Would it be possible to run the same C++ code simultaneously?

Say I compile some code and make it run. It will take 10 minutes to finish.

In the meantime, if I change some parameters in the code and compile it again using a separate terminal window and run it too (so there's now two programs running simultaneously using the same code), does the second run affect the first running program as the first compiled output is replaced by the second compiled output?

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

0

The behavior isn't defined by the C++ standard. In general, one of two things will happen (depends primarily on operating system)

  1. The second compilation will fail because the linker won't be able to open the executable file to write to it.

  2. Compilation will succeed, and existing invocations of the original executable will be unaffected; later invocations will use the new executable.

The third possibility -- the compilation succeeds, and messes up existing invocations -- is unheard-of in modern operating systems.

over 4 years ago · Santiago Trujillo Relatório

0

The only reasonable answer is that the behaviour is entirely contingent on the operating system: the C++ standard makes no attempt to describe what could happen.

You operating system vendor might extend the common courtesy of documenting or specifying the behaviour but I've never seen such documentation.

Your best bet is to not attempt this.


I'm an old cat, here are some musings. It's unlikely you could do this on Windows due to file locking. On Sun workstations it's possible but the program doesn't seem to work well at all once you compile into the same location as a running executable. Well it was certainly like that when I was at University using pre-standardised C++. It simply behaved oddly and there's no accounting for it. On rhel it seems to work nicely for small programs in particular.

over 4 years ago · Santiago Trujillo Relatório

0

There are three possible scenarios:

  1. On Windows, an executable file will get locked for writing and removal while it is being executed so the build will just fail.

  2. On Linux, an executable file is not necessary protected from modification or removal while it is being executed.

2.1. If a file is deleted from the file system and then a new file is created with the same name then the old file content will still remain until already running executable exits while the new executable will use the new file. So the old executable will continue to run normally while the new one will be ready to work as well.

2.2. If a file is opened for writing and overwritten with new content then the already-running executable will be using the new machine code which is most likely be incompatible with the existing program state and will lead to crashes.

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