Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Okay to run multiple instances of the same executable?

Consider an executable named makecookie (plain old serial/non-parallelized program). I'd like to run two instances of it at the same time (by opening two terminals, for example), as follows:

First Terminal:

~/makecookie vanilla dataToRead.dat

Second Terminal:

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

The second argument is a configuration string and the 3rd argument is a data file to open and read. The result will be output to stdout on the terminal.

This causes the same executable to execute at the same time. Will there any issues with this? Why or why not?

like image 337
J. Sanders Avatar asked May 26 '16 04:05

J. Sanders


People also ask

How do I run two instances of the same program?

To open another window of a program, simply launch it again. An easier way to do this is to press and hold the Shift key and click on the program's icon in the taskbar. If the program allows multiple windows, then another instance will open up without a hinge.

Can we launch multiple instances?

Open multiple instances of an app using Shift + Click First, open the application you want to run in multiple instances.

How do I run two programs at the same time in Windows?

On the taskbar, select the Task view icon, then select New desktop. Open the apps you want to use on that desktop and then when you want to switch to a different desktop, select Task view again.

How do I block multiple instances of a program in Windows 10?

How do I stop multiple programs from running? On most Windows computers, you can access the Task Manager by pressing Ctrl+Shift+Esc, then clicking the Startup tab. Select any program in the list and click the Disable button if you don't want it to run on startup.


1 Answers

Running multiple instances of a same executable doesn't cause any issues. In the eyes of operating system they are two different processes. Each instance have their own page tables, file descriptors, stack, PID etc.., which are independent of all other instances.

But when you are accessing a same resource on different processes then you have to synchronize the resource access by using any of the lock strategies. For example two instances writing to a same file will result in clutters in the file where one instance could possibly write in the middle of an another instance's data.

Two instances reading from a same file won't be a problem, but when one writes and other reads the result will be messy. Note: Each instance will have their own read/write pointer where they are reading/writing independent of other instances.

As you are using the file dataToRead.dat purely for reading you won't get any issues.

Overall there is no issue in running multiple instances if you have properly synchronized the resource access.

like image 184
jblixr Avatar answered Sep 20 '22 08:09

jblixr