Running multiple shell instances with different parameters at the same time











up vote
0
down vote

favorite












Assume I have a python script that I want to run with different parameter combinations (I have MacBook Pro). If I use a shell script to do so (say run.sh), does it make sense to run run.sh multiple times at the same time, each of which in different parameter combinations? In order word, do different parameter combinations touch each other while both are running in the memory? Is this something like the concept of memory protection?










share|improve this question


























    up vote
    0
    down vote

    favorite












    Assume I have a python script that I want to run with different parameter combinations (I have MacBook Pro). If I use a shell script to do so (say run.sh), does it make sense to run run.sh multiple times at the same time, each of which in different parameter combinations? In order word, do different parameter combinations touch each other while both are running in the memory? Is this something like the concept of memory protection?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Assume I have a python script that I want to run with different parameter combinations (I have MacBook Pro). If I use a shell script to do so (say run.sh), does it make sense to run run.sh multiple times at the same time, each of which in different parameter combinations? In order word, do different parameter combinations touch each other while both are running in the memory? Is this something like the concept of memory protection?










      share|improve this question













      Assume I have a python script that I want to run with different parameter combinations (I have MacBook Pro). If I use a shell script to do so (say run.sh), does it make sense to run run.sh multiple times at the same time, each of which in different parameter combinations? In order word, do different parameter combinations touch each other while both are running in the memory? Is this something like the concept of memory protection?







      shell-script osx memory virtual-memory






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 17 at 23:00









      Katherine

      324




      324






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          This depends very much on what the python script and run.sh does.



          So let's take a very simple example:



          #!/bin/bash

          s=$(( RANDOM%5 ))
          echo Sleeping for $s > /tmp/foo
          sleep $s
          echo You entered $1 >> /tmp/foo
          cat /tmp/foo


          Now if I did



          ./run.sh 1 &
          ./run.sh 2 &
          ./run.sh 3 &


          I will have no idea what the output would be. That's because the script has a single resource (/tmp/foo) that can not be accessed multiple times; one script will overwrite the results of another.



          If, instead, the script was written to use properly unique "temporary" resources then it can be called multiple times:



          #!/bin/bash

          tmpfile=$(mktemp)

          s=$(( RANDOM%5 ))
          echo Sleeping for $s > $tmpfile
          sleep $s
          echo You entered $1 >> $tmpfile
          cat $tmpfile
          rm $tmpfile


          Now you can call this as many times as you like, and it will work properly.



          Well... given memory and CPU limits, of course!






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424875%2frunning-multiple-shell-instances-with-different-parameters-at-the-same-time%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            This depends very much on what the python script and run.sh does.



            So let's take a very simple example:



            #!/bin/bash

            s=$(( RANDOM%5 ))
            echo Sleeping for $s > /tmp/foo
            sleep $s
            echo You entered $1 >> /tmp/foo
            cat /tmp/foo


            Now if I did



            ./run.sh 1 &
            ./run.sh 2 &
            ./run.sh 3 &


            I will have no idea what the output would be. That's because the script has a single resource (/tmp/foo) that can not be accessed multiple times; one script will overwrite the results of another.



            If, instead, the script was written to use properly unique "temporary" resources then it can be called multiple times:



            #!/bin/bash

            tmpfile=$(mktemp)

            s=$(( RANDOM%5 ))
            echo Sleeping for $s > $tmpfile
            sleep $s
            echo You entered $1 >> $tmpfile
            cat $tmpfile
            rm $tmpfile


            Now you can call this as many times as you like, and it will work properly.



            Well... given memory and CPU limits, of course!






            share|improve this answer

























              up vote
              1
              down vote



              accepted










              This depends very much on what the python script and run.sh does.



              So let's take a very simple example:



              #!/bin/bash

              s=$(( RANDOM%5 ))
              echo Sleeping for $s > /tmp/foo
              sleep $s
              echo You entered $1 >> /tmp/foo
              cat /tmp/foo


              Now if I did



              ./run.sh 1 &
              ./run.sh 2 &
              ./run.sh 3 &


              I will have no idea what the output would be. That's because the script has a single resource (/tmp/foo) that can not be accessed multiple times; one script will overwrite the results of another.



              If, instead, the script was written to use properly unique "temporary" resources then it can be called multiple times:



              #!/bin/bash

              tmpfile=$(mktemp)

              s=$(( RANDOM%5 ))
              echo Sleeping for $s > $tmpfile
              sleep $s
              echo You entered $1 >> $tmpfile
              cat $tmpfile
              rm $tmpfile


              Now you can call this as many times as you like, and it will work properly.



              Well... given memory and CPU limits, of course!






              share|improve this answer























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                This depends very much on what the python script and run.sh does.



                So let's take a very simple example:



                #!/bin/bash

                s=$(( RANDOM%5 ))
                echo Sleeping for $s > /tmp/foo
                sleep $s
                echo You entered $1 >> /tmp/foo
                cat /tmp/foo


                Now if I did



                ./run.sh 1 &
                ./run.sh 2 &
                ./run.sh 3 &


                I will have no idea what the output would be. That's because the script has a single resource (/tmp/foo) that can not be accessed multiple times; one script will overwrite the results of another.



                If, instead, the script was written to use properly unique "temporary" resources then it can be called multiple times:



                #!/bin/bash

                tmpfile=$(mktemp)

                s=$(( RANDOM%5 ))
                echo Sleeping for $s > $tmpfile
                sleep $s
                echo You entered $1 >> $tmpfile
                cat $tmpfile
                rm $tmpfile


                Now you can call this as many times as you like, and it will work properly.



                Well... given memory and CPU limits, of course!






                share|improve this answer












                This depends very much on what the python script and run.sh does.



                So let's take a very simple example:



                #!/bin/bash

                s=$(( RANDOM%5 ))
                echo Sleeping for $s > /tmp/foo
                sleep $s
                echo You entered $1 >> /tmp/foo
                cat /tmp/foo


                Now if I did



                ./run.sh 1 &
                ./run.sh 2 &
                ./run.sh 3 &


                I will have no idea what the output would be. That's because the script has a single resource (/tmp/foo) that can not be accessed multiple times; one script will overwrite the results of another.



                If, instead, the script was written to use properly unique "temporary" resources then it can be called multiple times:



                #!/bin/bash

                tmpfile=$(mktemp)

                s=$(( RANDOM%5 ))
                echo Sleeping for $s > $tmpfile
                sleep $s
                echo You entered $1 >> $tmpfile
                cat $tmpfile
                rm $tmpfile


                Now you can call this as many times as you like, and it will work properly.



                Well... given memory and CPU limits, of course!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 18 at 1:30









                Stephen Harris

                22.8k24176




                22.8k24176






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f424875%2frunning-multiple-shell-instances-with-different-parameters-at-the-same-time%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre