How to know which command is being executed without stopping it?











up vote
19
down vote

favorite
7












In my example, I am running a command that takes very long to be executed (several hours).



I don't really remember if I entered make or make -j4.



Of course I could stop it and press up key or check history to know it, but that would stop the process and I don't want that to happen (in case it is already doing make -j4).



Is there any way to know which command is being executed without stopping the process?










share|improve this question




















  • 5




    From another terminal, try pgrep -a make
    – John1024
    Dec 5 at 8:48








  • 2




    that was it, thanks @John1024
    – Daniel Viaño
    Dec 5 at 8:56






  • 2




    In the case of make you can stop and restart it and it should pick up where it left off.
    – immibis
    Dec 6 at 5:42















up vote
19
down vote

favorite
7












In my example, I am running a command that takes very long to be executed (several hours).



I don't really remember if I entered make or make -j4.



Of course I could stop it and press up key or check history to know it, but that would stop the process and I don't want that to happen (in case it is already doing make -j4).



Is there any way to know which command is being executed without stopping the process?










share|improve this question




















  • 5




    From another terminal, try pgrep -a make
    – John1024
    Dec 5 at 8:48








  • 2




    that was it, thanks @John1024
    – Daniel Viaño
    Dec 5 at 8:56






  • 2




    In the case of make you can stop and restart it and it should pick up where it left off.
    – immibis
    Dec 6 at 5:42













up vote
19
down vote

favorite
7









up vote
19
down vote

favorite
7






7





In my example, I am running a command that takes very long to be executed (several hours).



I don't really remember if I entered make or make -j4.



Of course I could stop it and press up key or check history to know it, but that would stop the process and I don't want that to happen (in case it is already doing make -j4).



Is there any way to know which command is being executed without stopping the process?










share|improve this question















In my example, I am running a command that takes very long to be executed (several hours).



I don't really remember if I entered make or make -j4.



Of course I could stop it and press up key or check history to know it, but that would stop the process and I don't want that to happen (in case it is already doing make -j4).



Is there any way to know which command is being executed without stopping the process?







command-line make






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 at 16:40









muru

135k20289492




135k20289492










asked Dec 5 at 8:44









Daniel Viaño

10915




10915








  • 5




    From another terminal, try pgrep -a make
    – John1024
    Dec 5 at 8:48








  • 2




    that was it, thanks @John1024
    – Daniel Viaño
    Dec 5 at 8:56






  • 2




    In the case of make you can stop and restart it and it should pick up where it left off.
    – immibis
    Dec 6 at 5:42














  • 5




    From another terminal, try pgrep -a make
    – John1024
    Dec 5 at 8:48








  • 2




    that was it, thanks @John1024
    – Daniel Viaño
    Dec 5 at 8:56






  • 2




    In the case of make you can stop and restart it and it should pick up where it left off.
    – immibis
    Dec 6 at 5:42








5




5




From another terminal, try pgrep -a make
– John1024
Dec 5 at 8:48






From another terminal, try pgrep -a make
– John1024
Dec 5 at 8:48






2




2




that was it, thanks @John1024
– Daniel Viaño
Dec 5 at 8:56




that was it, thanks @John1024
– Daniel Viaño
Dec 5 at 8:56




2




2




In the case of make you can stop and restart it and it should pick up where it left off.
– immibis
Dec 6 at 5:42




In the case of make you can stop and restart it and it should pick up where it left off.
– immibis
Dec 6 at 5:42










4 Answers
4






active

oldest

votes

















up vote
32
down vote



accepted










If you want to see the full command line for every instance of make that is running on your computer, open a new terminal and try:



pgrep -a make


pgrep is a program that searches through all processes on your computer. In this case, it is looking for programs named make. The option -a tells pgrep to list both the process ID and the full command line for each matching process. (Without -a, it would just return the process ID.) For more information on pgrep's many options, see man pgrep.






share|improve this answer

















  • 7




    This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
    – kasperd
    Dec 5 at 12:50


















up vote
27
down vote













While the terminal window is active you can pause (suspend) the process by pressing Ctrl+Z. You can then push the job in the background by typing bg (your job will now continue in the background and you can at the same time work on the command line; this is equivalent to starting a job with & at the end of the command line). Then use cursor-arrows (up and down) to see which command you used. If you want (but this is not necessary) you can then get your job to the foreground by typing fg.






share|improve this answer



















  • 7




    This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
    – kasperd
    Dec 5 at 12:46






  • 11




    @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
    – penguin359
    Dec 5 at 20:26










  • @kasperd Not in bash, but they do in zsh.
    – JoL
    Dec 5 at 22:08






  • 4




    No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
    – Konrad Rudolph
    Dec 6 at 14:22


















up vote
10
down vote













I do something like Stefan: ^Z to pause the job, and then I run jobs. If you have multiple processes running, you may have to sort out which job was the one you paused, but this generally will give the command line. Then run fg to continue execution.






share|improve this answer




























    up vote
    1
    down vote













    A good way to see this dynamically is to run top, and this tells you overall system state and the running processes on the system.



    Doing a 'ps ux' shows your processes along with pid and other info, you can use skill to kill some of them off if you desire, man page for that is a good resource, and doing a skill or kill -9 gets sticky processes hung in device waits etc. You can also send other signals to processes such as -hup, gets daemons restarted etc.



    Top is nice since it shows you process size, elapsed time, and current cpu states and that of memory and swap.



    I often do a $make >& make.out& and then less or tail -f on the make.out log file. Since now make is detached as a process from my shell session.






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "89"
      };
      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: 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%2faskubuntu.com%2fquestions%2f1098580%2fhow-to-know-which-command-is-being-executed-without-stopping-it%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      32
      down vote



      accepted










      If you want to see the full command line for every instance of make that is running on your computer, open a new terminal and try:



      pgrep -a make


      pgrep is a program that searches through all processes on your computer. In this case, it is looking for programs named make. The option -a tells pgrep to list both the process ID and the full command line for each matching process. (Without -a, it would just return the process ID.) For more information on pgrep's many options, see man pgrep.






      share|improve this answer

















      • 7




        This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
        – kasperd
        Dec 5 at 12:50















      up vote
      32
      down vote



      accepted










      If you want to see the full command line for every instance of make that is running on your computer, open a new terminal and try:



      pgrep -a make


      pgrep is a program that searches through all processes on your computer. In this case, it is looking for programs named make. The option -a tells pgrep to list both the process ID and the full command line for each matching process. (Without -a, it would just return the process ID.) For more information on pgrep's many options, see man pgrep.






      share|improve this answer

















      • 7




        This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
        – kasperd
        Dec 5 at 12:50













      up vote
      32
      down vote



      accepted







      up vote
      32
      down vote



      accepted






      If you want to see the full command line for every instance of make that is running on your computer, open a new terminal and try:



      pgrep -a make


      pgrep is a program that searches through all processes on your computer. In this case, it is looking for programs named make. The option -a tells pgrep to list both the process ID and the full command line for each matching process. (Without -a, it would just return the process ID.) For more information on pgrep's many options, see man pgrep.






      share|improve this answer












      If you want to see the full command line for every instance of make that is running on your computer, open a new terminal and try:



      pgrep -a make


      pgrep is a program that searches through all processes on your computer. In this case, it is looking for programs named make. The option -a tells pgrep to list both the process ID and the full command line for each matching process. (Without -a, it would just return the process ID.) For more information on pgrep's many options, see man pgrep.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Dec 5 at 9:33









      John1024

      9,7592434




      9,7592434








      • 7




        This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
        – kasperd
        Dec 5 at 12:50














      • 7




        This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
        – kasperd
        Dec 5 at 12:50








      7




      7




      This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
      – kasperd
      Dec 5 at 12:50




      This is useful for simple cases like the one in the question. However if the command involved pipelines, loops, sequences of commands, internal commands, or variable expansion what you'd find with pgrep would look different from the command which was typed on the command line.
      – kasperd
      Dec 5 at 12:50












      up vote
      27
      down vote













      While the terminal window is active you can pause (suspend) the process by pressing Ctrl+Z. You can then push the job in the background by typing bg (your job will now continue in the background and you can at the same time work on the command line; this is equivalent to starting a job with & at the end of the command line). Then use cursor-arrows (up and down) to see which command you used. If you want (but this is not necessary) you can then get your job to the foreground by typing fg.






      share|improve this answer



















      • 7




        This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
        – kasperd
        Dec 5 at 12:46






      • 11




        @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
        – penguin359
        Dec 5 at 20:26










      • @kasperd Not in bash, but they do in zsh.
        – JoL
        Dec 5 at 22:08






      • 4




        No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
        – Konrad Rudolph
        Dec 6 at 14:22















      up vote
      27
      down vote













      While the terminal window is active you can pause (suspend) the process by pressing Ctrl+Z. You can then push the job in the background by typing bg (your job will now continue in the background and you can at the same time work on the command line; this is equivalent to starting a job with & at the end of the command line). Then use cursor-arrows (up and down) to see which command you used. If you want (but this is not necessary) you can then get your job to the foreground by typing fg.






      share|improve this answer



















      • 7




        This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
        – kasperd
        Dec 5 at 12:46






      • 11




        @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
        – penguin359
        Dec 5 at 20:26










      • @kasperd Not in bash, but they do in zsh.
        – JoL
        Dec 5 at 22:08






      • 4




        No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
        – Konrad Rudolph
        Dec 6 at 14:22













      up vote
      27
      down vote










      up vote
      27
      down vote









      While the terminal window is active you can pause (suspend) the process by pressing Ctrl+Z. You can then push the job in the background by typing bg (your job will now continue in the background and you can at the same time work on the command line; this is equivalent to starting a job with & at the end of the command line). Then use cursor-arrows (up and down) to see which command you used. If you want (but this is not necessary) you can then get your job to the foreground by typing fg.






      share|improve this answer














      While the terminal window is active you can pause (suspend) the process by pressing Ctrl+Z. You can then push the job in the background by typing bg (your job will now continue in the background and you can at the same time work on the command line; this is equivalent to starting a job with & at the end of the command line). Then use cursor-arrows (up and down) to see which command you used. If you want (but this is not necessary) you can then get your job to the foreground by typing fg.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 13 at 7:10









      Kulfy

      2,72331034




      2,72331034










      answered Dec 5 at 9:59









      Stefan

      28326




      28326








      • 7




        This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
        – kasperd
        Dec 5 at 12:46






      • 11




        @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
        – penguin359
        Dec 5 at 20:26










      • @kasperd Not in bash, but they do in zsh.
        – JoL
        Dec 5 at 22:08






      • 4




        No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
        – Konrad Rudolph
        Dec 6 at 14:22














      • 7




        This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
        – kasperd
        Dec 5 at 12:46






      • 11




        @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
        – penguin359
        Dec 5 at 20:26










      • @kasperd Not in bash, but they do in zsh.
        – JoL
        Dec 5 at 22:08






      • 4




        No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
        – Konrad Rudolph
        Dec 6 at 14:22








      7




      7




      This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
      – kasperd
      Dec 5 at 12:46




      This works with some commands but not all. For example if you typed a loop like for X in {1..1000} ; do sleep $X ; done then the loop would be interrupted and remaining iterations would not happen.
      – kasperd
      Dec 5 at 12:46




      11




      11




      @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
      – penguin359
      Dec 5 at 20:26




      @kasperd Yes, quite annoying if you ask me, but I discovered a cool workaround for that issue. Surround a complicated command like that in parenthesis so it's a subshell. Then Ctrl-Z will suspend the whole subshell and resume correctly.
      – penguin359
      Dec 5 at 20:26












      @kasperd Not in bash, but they do in zsh.
      – JoL
      Dec 5 at 22:08




      @kasperd Not in bash, but they do in zsh.
      – JoL
      Dec 5 at 22:08




      4




      4




      No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
      – Konrad Rudolph
      Dec 6 at 14:22




      No need to put the job into the background: it’s sufficient to suspend it, check the history (or jobs, as shown in @ichabod’s answer), and then resuming it via fg.
      – Konrad Rudolph
      Dec 6 at 14:22










      up vote
      10
      down vote













      I do something like Stefan: ^Z to pause the job, and then I run jobs. If you have multiple processes running, you may have to sort out which job was the one you paused, but this generally will give the command line. Then run fg to continue execution.






      share|improve this answer

























        up vote
        10
        down vote













        I do something like Stefan: ^Z to pause the job, and then I run jobs. If you have multiple processes running, you may have to sort out which job was the one you paused, but this generally will give the command line. Then run fg to continue execution.






        share|improve this answer























          up vote
          10
          down vote










          up vote
          10
          down vote









          I do something like Stefan: ^Z to pause the job, and then I run jobs. If you have multiple processes running, you may have to sort out which job was the one you paused, but this generally will give the command line. Then run fg to continue execution.






          share|improve this answer












          I do something like Stefan: ^Z to pause the job, and then I run jobs. If you have multiple processes running, you may have to sort out which job was the one you paused, but this generally will give the command line. Then run fg to continue execution.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 5 at 20:39









          ichabod

          1112




          1112






















              up vote
              1
              down vote













              A good way to see this dynamically is to run top, and this tells you overall system state and the running processes on the system.



              Doing a 'ps ux' shows your processes along with pid and other info, you can use skill to kill some of them off if you desire, man page for that is a good resource, and doing a skill or kill -9 gets sticky processes hung in device waits etc. You can also send other signals to processes such as -hup, gets daemons restarted etc.



              Top is nice since it shows you process size, elapsed time, and current cpu states and that of memory and swap.



              I often do a $make >& make.out& and then less or tail -f on the make.out log file. Since now make is detached as a process from my shell session.






              share|improve this answer

























                up vote
                1
                down vote













                A good way to see this dynamically is to run top, and this tells you overall system state and the running processes on the system.



                Doing a 'ps ux' shows your processes along with pid and other info, you can use skill to kill some of them off if you desire, man page for that is a good resource, and doing a skill or kill -9 gets sticky processes hung in device waits etc. You can also send other signals to processes such as -hup, gets daemons restarted etc.



                Top is nice since it shows you process size, elapsed time, and current cpu states and that of memory and swap.



                I often do a $make >& make.out& and then less or tail -f on the make.out log file. Since now make is detached as a process from my shell session.






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  A good way to see this dynamically is to run top, and this tells you overall system state and the running processes on the system.



                  Doing a 'ps ux' shows your processes along with pid and other info, you can use skill to kill some of them off if you desire, man page for that is a good resource, and doing a skill or kill -9 gets sticky processes hung in device waits etc. You can also send other signals to processes such as -hup, gets daemons restarted etc.



                  Top is nice since it shows you process size, elapsed time, and current cpu states and that of memory and swap.



                  I often do a $make >& make.out& and then less or tail -f on the make.out log file. Since now make is detached as a process from my shell session.






                  share|improve this answer












                  A good way to see this dynamically is to run top, and this tells you overall system state and the running processes on the system.



                  Doing a 'ps ux' shows your processes along with pid and other info, you can use skill to kill some of them off if you desire, man page for that is a good resource, and doing a skill or kill -9 gets sticky processes hung in device waits etc. You can also send other signals to processes such as -hup, gets daemons restarted etc.



                  Top is nice since it shows you process size, elapsed time, and current cpu states and that of memory and swap.



                  I often do a $make >& make.out& and then less or tail -f on the make.out log file. Since now make is detached as a process from my shell session.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 6 at 17:02







                  user900446





































                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Ask Ubuntu!


                      • 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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2faskubuntu.com%2fquestions%2f1098580%2fhow-to-know-which-command-is-being-executed-without-stopping-it%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

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                       ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕