set a name to sleep process in shell










0















I'm a newbie to linux and has a task of writing a script to automate some work



Currently I have a script (runme.csh) with content like this



#!/bin/csh -f

read some settings from a file>

while (some condition)

< do some work >

sleep 600

end


Now I need to run copies of the script multiple times (copy the script to new file name and run) on same shell [tcsh]



example



[aruna>] runme1.csh &



[aruna>] runme2.csh &



[aruna>] runme3.csh &



Now if I wanted to kill one run I can do ps, find the PID of respective script by its name and kill. However I have no way to find the pid of the sleep command that script executed.



Is there a way to give a name to the sleep process so that I can see which sleep process is executed by which script?



Thank you :)










share|improve this question


























    0















    I'm a newbie to linux and has a task of writing a script to automate some work



    Currently I have a script (runme.csh) with content like this



    #!/bin/csh -f

    read some settings from a file>

    while (some condition)

    < do some work >

    sleep 600

    end


    Now I need to run copies of the script multiple times (copy the script to new file name and run) on same shell [tcsh]



    example



    [aruna>] runme1.csh &



    [aruna>] runme2.csh &



    [aruna>] runme3.csh &



    Now if I wanted to kill one run I can do ps, find the PID of respective script by its name and kill. However I have no way to find the pid of the sleep command that script executed.



    Is there a way to give a name to the sleep process so that I can see which sleep process is executed by which script?



    Thank you :)










    share|improve this question
























      0












      0








      0








      I'm a newbie to linux and has a task of writing a script to automate some work



      Currently I have a script (runme.csh) with content like this



      #!/bin/csh -f

      read some settings from a file>

      while (some condition)

      < do some work >

      sleep 600

      end


      Now I need to run copies of the script multiple times (copy the script to new file name and run) on same shell [tcsh]



      example



      [aruna>] runme1.csh &



      [aruna>] runme2.csh &



      [aruna>] runme3.csh &



      Now if I wanted to kill one run I can do ps, find the PID of respective script by its name and kill. However I have no way to find the pid of the sleep command that script executed.



      Is there a way to give a name to the sleep process so that I can see which sleep process is executed by which script?



      Thank you :)










      share|improve this question














      I'm a newbie to linux and has a task of writing a script to automate some work



      Currently I have a script (runme.csh) with content like this



      #!/bin/csh -f

      read some settings from a file>

      while (some condition)

      < do some work >

      sleep 600

      end


      Now I need to run copies of the script multiple times (copy the script to new file name and run) on same shell [tcsh]



      example



      [aruna>] runme1.csh &



      [aruna>] runme2.csh &



      [aruna>] runme3.csh &



      Now if I wanted to kill one run I can do ps, find the PID of respective script by its name and kill. However I have no way to find the pid of the sleep command that script executed.



      Is there a way to give a name to the sleep process so that I can see which sleep process is executed by which script?



      Thank you :)







      shell process sleep






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 4:18









      Aruna RubasingheAruna Rubasinghe

      61




      61






















          1 Answer
          1






          active

          oldest

          votes


















          0














          It seems that you can't properly do that using bash alone, as exec -a foo sleep 100 still shows up as sleep when using ps:



          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          101468 pts/8 00:00:00 bash
          101494 pts/8 00:00:00 sleep


          But using Perl, you can easily change the name of the process because Perl supports
          assignment to $0 (the name of the process, in Perl):



          perl -wle '$0=shift;sleep shift' sleeper 100

          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          100740 pts/8 00:00:00 bash
          104067 pts/8 00:00:00 sleeper


          The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given.






          share|improve this answer























          • Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

            – Aruna Rubasinghe
            Nov 16 '18 at 1:46











          • @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

            – Corion
            Nov 16 '18 at 7:17










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f53312374%2fset-a-name-to-sleep-process-in-shell%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









          0














          It seems that you can't properly do that using bash alone, as exec -a foo sleep 100 still shows up as sleep when using ps:



          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          101468 pts/8 00:00:00 bash
          101494 pts/8 00:00:00 sleep


          But using Perl, you can easily change the name of the process because Perl supports
          assignment to $0 (the name of the process, in Perl):



          perl -wle '$0=shift;sleep shift' sleeper 100

          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          100740 pts/8 00:00:00 bash
          104067 pts/8 00:00:00 sleeper


          The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given.






          share|improve this answer























          • Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

            – Aruna Rubasinghe
            Nov 16 '18 at 1:46











          • @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

            – Corion
            Nov 16 '18 at 7:17















          0














          It seems that you can't properly do that using bash alone, as exec -a foo sleep 100 still shows up as sleep when using ps:



          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          101468 pts/8 00:00:00 bash
          101494 pts/8 00:00:00 sleep


          But using Perl, you can easily change the name of the process because Perl supports
          assignment to $0 (the name of the process, in Perl):



          perl -wle '$0=shift;sleep shift' sleeper 100

          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          100740 pts/8 00:00:00 bash
          104067 pts/8 00:00:00 sleeper


          The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given.






          share|improve this answer























          • Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

            – Aruna Rubasinghe
            Nov 16 '18 at 1:46











          • @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

            – Corion
            Nov 16 '18 at 7:17













          0












          0








          0







          It seems that you can't properly do that using bash alone, as exec -a foo sleep 100 still shows up as sleep when using ps:



          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          101468 pts/8 00:00:00 bash
          101494 pts/8 00:00:00 sleep


          But using Perl, you can easily change the name of the process because Perl supports
          assignment to $0 (the name of the process, in Perl):



          perl -wle '$0=shift;sleep shift' sleeper 100

          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          100740 pts/8 00:00:00 bash
          104067 pts/8 00:00:00 sleeper


          The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given.






          share|improve this answer













          It seems that you can't properly do that using bash alone, as exec -a foo sleep 100 still shows up as sleep when using ps:



          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          101468 pts/8 00:00:00 bash
          101494 pts/8 00:00:00 sleep


          But using Perl, you can easily change the name of the process because Perl supports
          assignment to $0 (the name of the process, in Perl):



          perl -wle '$0=shift;sleep shift' sleeper 100

          [~ ]$ ps -u corion
          PID TTY TIME CMD
          ...
          100740 pts/8 00:00:00 bash
          104067 pts/8 00:00:00 sleeper


          The above oneliner changes the name to the first argument given and then sleeps as many seconds as the second argument given.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 11:58









          CorionCorion

          3,33911126




          3,33911126












          • Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

            – Aruna Rubasinghe
            Nov 16 '18 at 1:46











          • @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

            – Corion
            Nov 16 '18 at 7:17

















          • Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

            – Aruna Rubasinghe
            Nov 16 '18 at 1:46











          • @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

            – Corion
            Nov 16 '18 at 7:17
















          Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

          – Aruna Rubasinghe
          Nov 16 '18 at 1:46





          Hi Corion,Thanks for your valuable input. But it didn't work. I can see "perl" as the process, not "sleeper"

          – Aruna Rubasinghe
          Nov 16 '18 at 1:46













          @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

          – Corion
          Nov 16 '18 at 7:17





          @arunarubashinghe: Oh, that's bad - on RHEL6 (with whatever kernel) that worked, and on a Debian 9.5 3.16.43-2+deb8u2 kernel, it also works.

          – Corion
          Nov 16 '18 at 7:17



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312374%2fset-a-name-to-sleep-process-in-shell%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







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3