Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!