Prior has been known to use Ctrl + Z Suspend the foreground process to stop the process running, then switch to the background process to the foreground, so that you can continue to run through the shell of job control (jobs / fg N).
Recently we learned a new approach for the foreground process has kept output console, you can use Ctrl + S to STOP output of a process, in order to suspend the process.
You can restart after (START) process by Ctrl + Q output or input any character to continue to run.
See this method, immediately think of to write a script to test:
1 #! /bin/sh 2 var=1 3 while : 4 do 5 echo this is $var 6 var=$(($var+1)) 7 usleep 100000 8 done
This script outputs a log "this is N" every 100 ms, where N is the log sequence number, can help us determine between a pause and restart if the output is lost.
During operation press Ctrl + S, indeed suspended output:
>./deadloop.sh this is 1 this is 2 this is 3 this is 4
Then press Ctrl + Q output continues until you press Ctrl + Z Suspend process:
>./deadloop.sh this is 1 this is 2 this is 3 this is 4 this is 5 this is 6 this is 7 this is 8 this is 9 this is 10 this is 11 ^ Z [1]+ Stopped ./deadloop.sh >
First, you can see the output after the restart and serial number can be connected before the restart, so the middle and there is no output loss, that is to say the process was suspended, not just output was stopped.
Secondly pressing Ctrl + Z When the terminal will display a ^ Z, and press Ctrl + S or Ctrl + Q, then the terminal does not have any echo.
So the focus of contrast when pressing Ctrl + S status when Z and Ctrl + process, the difference between these two ways of suspended point of view.
Ps command to view the status of both pause the process:
Ctrl+S
> ps xfo pid, ppid, pgid, sid, tpgid south, euid, user, stat, tty, command
PID PPID PGID SID TPGID SOUTH EUID USER STAT AT COMMAND 6653 6652 2786 2786 -1,500,500 Yunhai S? \ _ Gnome-pty-helper 6655 6652 6655 6655 6655 500 500 yunhai Ss + pts / 0 \ _ / bin / bash 12539 6652 12539 12539 16673 500 500 yunhai Ss pts / 1 \ _ / bin / bash 16673 12539 16673 12539 16673 500 500 yunhai S + pts / 1 | \ _ / bin / sh ./deadloop.sh 12797 6652 12797 12797 13349 500 500 yunhai Ss pts / 2 \ _ / bin / bash 15959 6652 15959 15959 16766 500 500 yunhai Ss pts / 3 \ _ / bin / bash 16766 15959 16766 15959 16766 500 500 yunhai R+ pts/3 \_ ps xfo pid,ppid,pgid,sid,tpgid,suid,euid,user,stat,tty,command
Ctrl+Z
>ps xfo pid,ppid,pgid,sid,tpgid,suid,euid,user,stat,tty,command PID PPID PGID SID TPGID SOUTH EUID USER STAT AT COMMAND 6653 6652 2786 2786 -1,500,500 Yunhai S? \ _ Gnome-pty-helper 6655 6652 6655 6655 6655 500 500 yunhai Ss + pts / 0 \ _ / bin / bash 12539 12539 12539 6652 16717 500 500 Yunhai Ss Pts / 1 \ _ / Bin / Bash 16673 12539 16673 12539 16717 500 500 Yunhai T Pts / 1 | \ _ / Bin / Sh ./Deadloop.Sh 16688 16673 16673 12539 16717 500 500 yunhai T pts / 1 | | \ _ usleep 100000 16717 12539 16717 12539 16717 500 500 yunhai R+ pts/1 | \_ ps xfo pid,ppid,pgid,sid,tpgid,suid,euid,user,stat,tty,command 12797 6652 12797 12797 13349 500 500 yunhai Ss pts / 2 \ _ / bin / bash 15959 6652 15959 15959 15959 500 500 yunhai Ss + pts / 3 \ _ / bin / bash
The biggest difference can be seen that by the process of Ctrl + Z stopped state pending ( 'T'), Ctrl + S is stopped by the processes running state ( 'S +').
On the other hand, we start stap detection process between the transceiver signal, you can receive the following output when Ctrl + Z to stop the process:
22 events/3 16688 usleep 20 SIGTSTP
22 events/3 16673 deadloop.sh 20 SIGTSTP
16673 deadloop.sh 12539 bash 17 SIGCHLD
16688 usleep 16673 deadloop.sh 17 SIGCHLD
That can be observed SIGTSTP process signals sent from the front desk. And when you use Ctrl + S is no particular signal is detected (SIGCHILD only sent to the parent process usleep at the end of the process).
Note: SIGCHLD here does not mean deadloop.sh and usleep end, but notification is sent to the parent process when suspended. In this regard, I can refer to an article written before:
[Apue] those things waiting for child process
During the pause, two ways to view the process stack information is suspended by pstack command:
Ctrl+S
>pstack 16673
#0 0x00119424 in __kernel_vsyscall ()
#1 0x007a7cd3 in __write_nocancel () from /lib/libc.so.6
#2 0x007411b4 in _IO_new_file_write () from /lib/libc.so.6
#3 0x00742a90 in _IO_new_do_write () from /lib/libc.so.6
#4 0x00741c80 in _IO_new_file_overflow () from /lib/libc.so.6
#5 0x00744b2a in __overflow () from /lib/libc.so.6
#6 0x0073e0b5 in putc () from /lib/libc.so.6
#7 0x080aebb0 in echo_builtin ()
#8 0x08070c51 in ?? ()
#9 0x08072e41 in ?? ()
#10 0x08073aa0 in execute_command_internal ()
#11 0x080747a4 in execute_command ()
#12 0x08076d89 in ?? ()
#13 0x08073a02 in execute_command_internal ()
#14 0x080747a4 in execute_command ()
#15 0x08076d89 in ?? ()
#16 0x08073a02 in execute_command_internal ()
#17 0x080747a4 in execute_command ()
#18 0x080750e4 in ?? ()
#19 0x08073bc4 in execute_command_internal ()
#20 0x080747a4 in execute_command ()
#21 0x08060857 in reader_loop ()
#22 0x0805fed9 in main ()
Ctrl+Z
>pstack 16673
#0 0x00119424 in __kernel_vsyscall ()
#1 0x00776673 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x080830f2 in ?? ()
#3 0x0808432e in wait_for ()
#4 0x08074635 in execute_command_internal ()
#5 0x08076dcd in ?? ()
#6 0x08073a02 in execute_command_internal ()
#7 0x080747a4 in execute_command ()
#8 0x080750e4 in ?? ()
#9 0x08073bc4 in execute_command_internal ()
#10 0x080747a4 in execute_command ()
#11 0x08060857 in reader_loop ()
#12 0x0805fed9 in main ()
The former stop on the write system call, which stopped at the waitpid system calls.
Therefore, the former should be suspended in the output, while the latter is suspended while waiting for usleep child process to return.
You can experience the subtle difference between these two ways at.
Finally, you can use the gadget Ctrl + S to stop a foreground process premise is required to open the IXON flag terminal, before using:
[Apue] a small tool to view the current terminal flag set
Can I view the input terminal of the flag has been opened this logo:
>./term input flag 0x00006f02 BRKINT ICRNL IMAXBEL IXANY IXON output flag 0x00000005 ONLCR OPOST control flag 0x000004bf CREAD CSIZE CS6 CS7 CS8 HUPCL local flag 0x00008a3b ECHO feedback ECHOK Ichhanon IEXTEN ITSELF
General terminal are open. If we open IXANY flag, you can use any key to restart stopped output, but do not have to use Ctrl + Q.
Finally, there is a hidden premise that the process was suspended in the foreground there are frequent output, or Ctrl + S is also useless.
In summary, today learned a new way to suspend a foreground process running, operation and maintenance for veterans who may have been Shoudaoqinlai, for me it is completely fresh,
So I spent some time researching the next, feeling linux profound, humble place might hide something good, it is worth digging!