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?
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
is a program that searches through all processes on your computer. In this case, it is looking for programs namedmake
. The option-a
tellspgrep
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, seeman pgrep
.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 typingfg
.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 runfg
to continue execution.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.