Shell script running binaries in multiple terminals

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.



I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.



#!/bin/bash
gnome-terminal -e "vi" & MAIN_PID=$!
gnome-terminal -e "gedit" & SIM_PID=$!
echo "MAIN Process ID is " $MAIN_PID
echo "SIM Process ID is " $SIM_PID
sudo kill $MAIN_PID


Terminal Output:



MAIN Process ID is 8532
SIM Process ID is 8542
# Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
# Use “-- ” to terminate the options and put the command line to execute after it.
kill: (8532): No such process
user:~/Desktop$ ps -A | grep vi
1026 ? 00:00:01 dconf-service
8541 pts/3 00:00:00 vi
user:~/Desktop$ ps -A | grep gedit
8550 pts/4 00:00:00 gedit


If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.










share|improve this question

























    up vote
    0
    down vote

    favorite












    I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.



    I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.



    #!/bin/bash
    gnome-terminal -e "vi" & MAIN_PID=$!
    gnome-terminal -e "gedit" & SIM_PID=$!
    echo "MAIN Process ID is " $MAIN_PID
    echo "SIM Process ID is " $SIM_PID
    sudo kill $MAIN_PID


    Terminal Output:



    MAIN Process ID is 8532
    SIM Process ID is 8542
    # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
    # Use “-- ” to terminate the options and put the command line to execute after it.
    kill: (8532): No such process
    user:~/Desktop$ ps -A | grep vi
    1026 ? 00:00:01 dconf-service
    8541 pts/3 00:00:00 vi
    user:~/Desktop$ ps -A | grep gedit
    8550 pts/4 00:00:00 gedit


    If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.



      I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.



      #!/bin/bash
      gnome-terminal -e "vi" & MAIN_PID=$!
      gnome-terminal -e "gedit" & SIM_PID=$!
      echo "MAIN Process ID is " $MAIN_PID
      echo "SIM Process ID is " $SIM_PID
      sudo kill $MAIN_PID


      Terminal Output:



      MAIN Process ID is 8532
      SIM Process ID is 8542
      # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
      # Use “-- ” to terminate the options and put the command line to execute after it.
      kill: (8532): No such process
      user:~/Desktop$ ps -A | grep vi
      1026 ? 00:00:01 dconf-service
      8541 pts/3 00:00:00 vi
      user:~/Desktop$ ps -A | grep gedit
      8550 pts/4 00:00:00 gedit


      If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.










      share|improve this question













      I'm pretty new to shell scripts but I have some binaries I'd like to run in a loop over a set of different input files. I need them to be run in sequence: repeat after current one complete.



      I got as far as trying to run two process in separate terminals and saving the pid but when I go to kill the process, it looks like the pids have changed.



      #!/bin/bash
      gnome-terminal -e "vi" & MAIN_PID=$!
      gnome-terminal -e "gedit" & SIM_PID=$!
      echo "MAIN Process ID is " $MAIN_PID
      echo "SIM Process ID is " $SIM_PID
      sudo kill $MAIN_PID


      Terminal Output:



      MAIN Process ID is 8532
      SIM Process ID is 8542
      # Option “-e” is deprecated and might be removed in a later version of gnome-terminal.
      # Use “-- ” to terminate the options and put the command line to execute after it.
      kill: (8532): No such process
      user:~/Desktop$ ps -A | grep vi
      1026 ? 00:00:01 dconf-service
      8541 pts/3 00:00:00 vi
      user:~/Desktop$ ps -A | grep gedit
      8550 pts/4 00:00:00 gedit


      If there's an easier way to get what I want started, I'd like to know as well. I was planning to start these processes and check some condition to know when they have completed, kill the process and repeat with different set of inputs.







      shell-script






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 23 at 14:36









      woahs

      1




      1




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          When you run gnome-terminal -e "vi" & MAIN_PID=$!, you are not capturing the PID of vi in MAIN_PID; you are capturing the PID of that instance of gnome-terminal. If you want to find the PID of a process owned by gnome_terminal, you could do some magic on the output of pstree:



          pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'


          To check whether a process still exists, you can use kill -0 which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.






          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: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f464421%2fshell-script-running-binaries-in-multiple-terminals%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            When you run gnome-terminal -e "vi" & MAIN_PID=$!, you are not capturing the PID of vi in MAIN_PID; you are capturing the PID of that instance of gnome-terminal. If you want to find the PID of a process owned by gnome_terminal, you could do some magic on the output of pstree:



            pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'


            To check whether a process still exists, you can use kill -0 which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.






            share|improve this answer
























              up vote
              0
              down vote













              When you run gnome-terminal -e "vi" & MAIN_PID=$!, you are not capturing the PID of vi in MAIN_PID; you are capturing the PID of that instance of gnome-terminal. If you want to find the PID of a process owned by gnome_terminal, you could do some magic on the output of pstree:



              pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'


              To check whether a process still exists, you can use kill -0 which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                When you run gnome-terminal -e "vi" & MAIN_PID=$!, you are not capturing the PID of vi in MAIN_PID; you are capturing the PID of that instance of gnome-terminal. If you want to find the PID of a process owned by gnome_terminal, you could do some magic on the output of pstree:



                pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'


                To check whether a process still exists, you can use kill -0 which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.






                share|improve this answer












                When you run gnome-terminal -e "vi" & MAIN_PID=$!, you are not capturing the PID of vi in MAIN_PID; you are capturing the PID of that instance of gnome-terminal. If you want to find the PID of a process owned by gnome_terminal, you could do some magic on the output of pstree:



                pstree -p $MAIN_PID | grep -o 'vim([0-9]*) | grep -o '[0-9]*'


                To check whether a process still exists, you can use kill -0 which will not send any signals, and either return with an exit code of 0 if the process exists, or 1 if it does not.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 23 at 15:51









                DopeGhoti

                41.1k55080




                41.1k55080



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464421%2fshell-script-running-binaries-in-multiple-terminals%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?