Is it okay to run multiple instances of the same executable?

Consider an executable file called makecookie (a regular old serial / non-parallel program). I would like to run two instances at the same time (by opening two terminals, for example):

First terminal:

 ~/makecookie vanilla dataToRead.dat 

The second terminal:

 cd ~ mkdir secondJar ln -s ~/makecookie secondJar/ secondJar/makecookie chocolate dataToRead.dat 

The second argument is the configuration line, and the third is the data file to open and read. The result will be displayed on stdout on the terminal.

This leads to the fact that the same executable file is executed simultaneously. Will there be problems with this? Why or why not?

+5
source share
1 answer

Running multiple instances of the same executable does not cause any problems. In the eyes of the operating system, these are two different processes. Each instance has its own page tables, file descriptors, stack, PID, etc., which are independent of all other instances.

But when you get access to the same resource in different processes, you need to synchronize access to resources using any of the blocking strategies. For example, two instances recording one file will lead to interference in the file, where one instance can write in the middle of another instance of the data.

Two instances read from one file will not be a problem, but when someone writes and the other reads, the result will be messy. Note. Each instance will have its own read / write pointer, where they read / write independently of other instances.

Since you are using the dataToRead.dat only dataToRead.dat file, you will not get any problems.

In general, there is no problem running multiple instances if you correctly synchronized access to resources.

+4
source

All Articles