Skip to content
Advertisement

Executing single shell script parallelly at same time with different arguments

Consider a script lets say test.sh which accepts file no as argument which process huge files based on argument. So whenever I am executing it as “nohup ./test.sh 01 &” it does the job, I have requirement where same needs to be executed parallelly for 8 files and I am able to achieve that with different arguments.

Following are my major queries on same:

  1. Whenever I am executing same script parallelly with different arguments are their any chances that one instance may alter another instance variables as I am using only one copy of script ?
  2. If no then how is this avoided or done, what avoids this conflict ?

Any reference to read on the same of brief explanation would be really helpful, thanks!!

Note: I have tried this approach & have observed no conflicts till date just want to know the reason behind the same as I am not able to find any reference for the same.

Advertisement

Answer

Much simplified, and thought as a startig point, only. Google for (unix) address space, or (unix) process image.

Most (all?) modern operating systems virtualize the memory (RAM), and call this address space, process image, or the like.

Each program is started in its own virtual address space, or process image, and it can only access the memory of its own address space. From a memory point of view this is as of each program was run on its own distinct computer (remember that I’m simplifying things).

Two programs running in parallel, cannot access data in each other’s address space, unless both programs have agreed for some sharing by using specific operating system services.

Back to your question: When you start multiple instances of a single program (a script is a program), a copy of this program is loaded into its own address space. Since the concept of the address space isolates the memory, all program data is isolated, too.

So, there is no danger that any data, e.g variables, of one program instance can be seen or modified by another program instance, unless the programs agreed upon some sharing (using operating system services).

HTH

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement