Why is process not exiting and how to get it to exit

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











up vote
0
down vote

favorite












I have a server I want to run (on one HTTP port), and then another script (which runs (temporarily) on another port).



I'm using a pipe in order to let these run concurrently, and brackets to group the commands such that sleep occurs first (the second script accesses the server started in the first, so there needs to be some time for the first to be set up).



It works fine, with the server getting started and the sleep and test file executing correctly thereafter, but the terminal process does not exit automatically after the test as it does when just running the script.



npm run start-json-server | sleep 1; node './test/index-cjs.js' ; 


What do I need to do to allow a natural exit (preferably without going through the trouble of finding the process and killing it)?



Update: I realized it was still running (duh) because the first script, as a server, doesn't terminate... But is there a way I can get it to terminate, again, preferably without finding its PID?










share|improve this question









New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Which terminal process you want to exit automatically?
    – ploth
    Oct 1 at 6:12










  • The start-json-server one--once the node test script is finished.
    – Brett Zamir
    Oct 1 at 6:14














up vote
0
down vote

favorite












I have a server I want to run (on one HTTP port), and then another script (which runs (temporarily) on another port).



I'm using a pipe in order to let these run concurrently, and brackets to group the commands such that sleep occurs first (the second script accesses the server started in the first, so there needs to be some time for the first to be set up).



It works fine, with the server getting started and the sleep and test file executing correctly thereafter, but the terminal process does not exit automatically after the test as it does when just running the script.



npm run start-json-server | sleep 1; node './test/index-cjs.js' ; 


What do I need to do to allow a natural exit (preferably without going through the trouble of finding the process and killing it)?



Update: I realized it was still running (duh) because the first script, as a server, doesn't terminate... But is there a way I can get it to terminate, again, preferably without finding its PID?










share|improve this question









New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Which terminal process you want to exit automatically?
    – ploth
    Oct 1 at 6:12










  • The start-json-server one--once the node test script is finished.
    – Brett Zamir
    Oct 1 at 6:14












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a server I want to run (on one HTTP port), and then another script (which runs (temporarily) on another port).



I'm using a pipe in order to let these run concurrently, and brackets to group the commands such that sleep occurs first (the second script accesses the server started in the first, so there needs to be some time for the first to be set up).



It works fine, with the server getting started and the sleep and test file executing correctly thereafter, but the terminal process does not exit automatically after the test as it does when just running the script.



npm run start-json-server | sleep 1; node './test/index-cjs.js' ; 


What do I need to do to allow a natural exit (preferably without going through the trouble of finding the process and killing it)?



Update: I realized it was still running (duh) because the first script, as a server, doesn't terminate... But is there a way I can get it to terminate, again, preferably without finding its PID?










share|improve this question









New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a server I want to run (on one HTTP port), and then another script (which runs (temporarily) on another port).



I'm using a pipe in order to let these run concurrently, and brackets to group the commands such that sleep occurs first (the second script accesses the server started in the first, so there needs to be some time for the first to be set up).



It works fine, with the server getting started and the sleep and test file executing correctly thereafter, but the terminal process does not exit automatically after the test as it does when just running the script.



npm run start-json-server | sleep 1; node './test/index-cjs.js' ; 


What do I need to do to allow a natural exit (preferably without going through the trouble of finding the process and killing it)?



Update: I realized it was still running (duh) because the first script, as a server, doesn't terminate... But is there a way I can get it to terminate, again, preferably without finding its PID?







shell npm






share|improve this question









New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Oct 1 at 6:06





















New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Oct 1 at 5:57









Brett Zamir

993




993




New contributor




Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Which terminal process you want to exit automatically?
    – ploth
    Oct 1 at 6:12










  • The start-json-server one--once the node test script is finished.
    – Brett Zamir
    Oct 1 at 6:14
















  • Which terminal process you want to exit automatically?
    – ploth
    Oct 1 at 6:12










  • The start-json-server one--once the node test script is finished.
    – Brett Zamir
    Oct 1 at 6:14















Which terminal process you want to exit automatically?
– ploth
Oct 1 at 6:12




Which terminal process you want to exit automatically?
– ploth
Oct 1 at 6:12












The start-json-server one--once the node test script is finished.
– Brett Zamir
Oct 1 at 6:14




The start-json-server one--once the node test script is finished.
– Brett Zamir
Oct 1 at 6:14










2 Answers
2






active

oldest

votes

















up vote
0
down vote













A pipe is not used for starting concurrent processes. It does do that, but it's mainly used for setting up a data stream between two stages of a pipeline.



Instead of your pipeline, use



npm run start-json-server &
server_pid="$!"

sleep 1

node ./test/index-cjs.js

kill "$server_pid"


This would start the first command in the background. There would then be a one second delay before the second command is started. When the second command finishes, the first command is killed.



The PID of the most recently started background process (a process started by using & at the end of it) is available as "$!", and here we use that fact to keep track of the PIDs of the first command.






share|improve this answer





























    up vote
    -1
    down vote













    I went ahead with this in getting the process:



    npm run start-json-server | grep '[n]ode test/server' 


    However, if someone has a cleaner answer, please let me know.






    share|improve this answer








    New contributor




    Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

















      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
      );



      );






      Brett Zamir is a new contributor. Be nice, and check out our Code of Conduct.









       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472501%2fwhy-is-process-not-exiting-and-how-to-get-it-to-exit%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      A pipe is not used for starting concurrent processes. It does do that, but it's mainly used for setting up a data stream between two stages of a pipeline.



      Instead of your pipeline, use



      npm run start-json-server &
      server_pid="$!"

      sleep 1

      node ./test/index-cjs.js

      kill "$server_pid"


      This would start the first command in the background. There would then be a one second delay before the second command is started. When the second command finishes, the first command is killed.



      The PID of the most recently started background process (a process started by using & at the end of it) is available as "$!", and here we use that fact to keep track of the PIDs of the first command.






      share|improve this answer


























        up vote
        0
        down vote













        A pipe is not used for starting concurrent processes. It does do that, but it's mainly used for setting up a data stream between two stages of a pipeline.



        Instead of your pipeline, use



        npm run start-json-server &
        server_pid="$!"

        sleep 1

        node ./test/index-cjs.js

        kill "$server_pid"


        This would start the first command in the background. There would then be a one second delay before the second command is started. When the second command finishes, the first command is killed.



        The PID of the most recently started background process (a process started by using & at the end of it) is available as "$!", and here we use that fact to keep track of the PIDs of the first command.






        share|improve this answer
























          up vote
          0
          down vote










          up vote
          0
          down vote









          A pipe is not used for starting concurrent processes. It does do that, but it's mainly used for setting up a data stream between two stages of a pipeline.



          Instead of your pipeline, use



          npm run start-json-server &
          server_pid="$!"

          sleep 1

          node ./test/index-cjs.js

          kill "$server_pid"


          This would start the first command in the background. There would then be a one second delay before the second command is started. When the second command finishes, the first command is killed.



          The PID of the most recently started background process (a process started by using & at the end of it) is available as "$!", and here we use that fact to keep track of the PIDs of the first command.






          share|improve this answer














          A pipe is not used for starting concurrent processes. It does do that, but it's mainly used for setting up a data stream between two stages of a pipeline.



          Instead of your pipeline, use



          npm run start-json-server &
          server_pid="$!"

          sleep 1

          node ./test/index-cjs.js

          kill "$server_pid"


          This would start the first command in the background. There would then be a one second delay before the second command is started. When the second command finishes, the first command is killed.



          The PID of the most recently started background process (a process started by using & at the end of it) is available as "$!", and here we use that fact to keep track of the PIDs of the first command.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 1 at 7:27

























          answered Oct 1 at 7:14









          Kusalananda

          108k14210333




          108k14210333






















              up vote
              -1
              down vote













              I went ahead with this in getting the process:



              npm run start-json-server | grep '[n]ode test/server' 


              However, if someone has a cleaner answer, please let me know.






              share|improve this answer








              New contributor




              Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                up vote
                -1
                down vote













                I went ahead with this in getting the process:



                npm run start-json-server | grep '[n]ode test/server' 


                However, if someone has a cleaner answer, please let me know.






                share|improve this answer








                New contributor




                Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



















                  up vote
                  -1
                  down vote










                  up vote
                  -1
                  down vote









                  I went ahead with this in getting the process:



                  npm run start-json-server | grep '[n]ode test/server' 


                  However, if someone has a cleaner answer, please let me know.






                  share|improve this answer








                  New contributor




                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  I went ahead with this in getting the process:



                  npm run start-json-server | grep '[n]ode test/server' 


                  However, if someone has a cleaner answer, please let me know.







                  share|improve this answer








                  New contributor




                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Oct 1 at 7:00









                  Brett Zamir

                  993




                  993




                  New contributor




                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Brett Zamir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




















                      Brett Zamir is a new contributor. Be nice, and check out our Code of Conduct.









                       

                      draft saved


                      draft discarded


















                      Brett Zamir is a new contributor. Be nice, and check out our Code of Conduct.












                      Brett Zamir is a new contributor. Be nice, and check out our Code of Conduct.











                      Brett Zamir is a new contributor. Be nice, and check out our Code of Conduct.













                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472501%2fwhy-is-process-not-exiting-and-how-to-get-it-to-exit%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?