Linux study notes (16) before and after Linux station handover process (fg / bg / jobs / ctrl + z)

Keywords: Linux front and back office process switch, linux process switch

fg, bg, jobs, &, ctrl + z are with system-related tasks, although it is basically not very need to use these commands, but also learn a very practical
one. Most often used &

   This command is used in a final, you can put this command into the background

 

$ pct &

二。ctrl + z

 

   A command being executed in the foreground can hang
III. jobs

     See how many commands are currently running in the background

The results of jobs executed, the + (plus sign) represents a current job, - (minus sign) is a representation of a job after the current job, jobs -l option to display all tasks PID.

state jobs may be running, stopped, Terminated, but if the task is terminated (kill), shell delete tasks from the current shell environment known list of process ID;

In other words, jobs command displays the current shell environment plays running in the background or suspended task information;

 

  1.  
    $ jobs -l
  2.  
    [ 1]+ 15432 Stopped (tty output) vim git.txt

[1] represents jobnumber is 1, PID is the process identification number, jobs in the state is stopped, followed by the command.

 

four. fg
     will command in the background adjusted to the front desk to continue running

     If you have multiple back-end command, you can call fg% jobnumber out the selected command, the command% jobnumber serial number is found in the background by the jobs command being executed (not pid)

 

  1.  
    $ fg %1
  2.  
    vim git.txt

Open git.txt with vim running in the foreground, which may be suspended ctrl + Z, bg i.e. running in the background.

 

Fives. bg

     A pause command in the background, becomes proceed

     By bg% num pending job can be stopped by the state instead of running, still in the background; if need be changed in the foreground, you can execute the command fg% num;

 

  1.  
    [ yanxia.dong@eslruntime07 ~]$ pct
  2.  
    # Keyboard input Ctrl + Z
  3.  
    ^ Z
  4.  
    [ 1]+ Stopped pct
  5.  
    [ yanxia.dong@eslruntime07 ~]$ jobs -l
  6.  
    [ 1]+ 5270 Stopped pct
  7.  
    [ yanxia.dong@eslruntime07 ~]$ bg %1
  8.  
    [ 1]+ pct &
  9.  
    [ yanxia.dong@eslruntime07 ~]$ jobs -l
  10.  
    [ 1]+ 5270 Running pct &

The above pct graphical user interface program. Non-graphical user interface is slightly different.

 

     If you have multiple back-end command, you can call bg% jobnumber out the selected command, the command% jobnumber serial number is found in the background by the jobs command being executed (not pid)

Linux using the Shell command under control tasks Jobs execute

the following command can be used to manipulate the process tasks:

  ps lists running processes in the system;

  It sends a signal to kill one or more processes (a process often used to kill);

  jobs listed in the job status of the current shell environment has been started, if not specified jobsid, task status information is displayed for all activities;

If the report of a task termination (ie, the task of the state is labeled Terminated), shell delete tasks from the current shell environment known list of process ID;

  bg move the process running in the background (Background);

  fg process will move to the foreground (Foreground); 

----- transferred to the job running in the background 

  If you often work in X graphics, you might have this experience: to run a GUI program through the terminal command, GUI interface out, but your terminal also stay in place, you can not continue with other commands in the shell, unless the GUI program off.

  In order to make the program after executing terminal can continue to accept commands, you can move the process running in the background, run the program using the following command: # Suppose you want to run xmms

  $ & pct

  after this open pct, suggesting the terminal back. Now pct yet run in the background; but if forget to use the "&" when you run the program, and do not want to re-run;

You can use the ctrl + z to suspend the program, and then typing bg command, so that the program continues to run in the background.

  The concept: the current task 

  if there is a background task number two, [1], [2]; if when the first successful implementation of a background task is completed, a second background task is still running, it will automatically become the current task background task number "[2]" background task.

So little can be drawn that the current task will change. When a user enters "fg", "bg" and "stop" and other commands, if you do not add any quotation marks, then the changes are the current task.

 

==== suspended foreground process: Ctrl + the Z-;

==== process termination:

    ---- terminate background processes:

   Method one: check the jobs command job number (assumed to be num), and then execute kill% $ kill% 1 num

   Method two: View job's process ID of the ps command (PID, assumed pid), then perform the kill pid $ kill 5270

    ---- terminate the foreground process: ctrl + c

  other role of kill: kill except that the signal can terminate the process, but also to send a signal to other processes using the kill -l can look kill supports. SIGTERM kill signal is transmitted without parameters,

It means to termination of the process, but the implementation process will have to see whether or not supported. If the process has not been terminated, you can use kill -SIGKILL pid, which is terminated by the kernel process, the process can not monitor this signal. 

==============================================================================================================

         ctrl + c forced to interrupt the execution of the current program.

         ctrl + d represents the end of the current input (i.e., the user no longer gives an instruction to the current program), then ends the current procedure usually Linux.

         ctrl + z represents the current foreground running in the background and often hangs. For it to continue running in the background, required "bg process ID" so that it continues to run; then "fg process number" to the foreground of the background process .

 

----- ctrl + c, ctrl + d, ctrl + z significance in linux:

        ctrl-c SIGINT signal is sent to all processes in the foreground process group. Often used to terminate the running program.
        ctrl-z SIGTSTP transmits a signal to all processes in the foreground process group commonly employed to suspend a process.
        ctrl-d is not a transmission signal, but rather a particular binary value indicates EOF.
        ctrl- \ SIGQUIT send a signal to all processes in the foreground process group to terminate the foreground process and generates core file.

-----  Key Function
        Ctrl-c Kill foreground process
        Ctrl-z Suspend foreground process
        Ctrl-d Terminate input, or exit shell
        Ctrl-s Suspend output
        Ctrl-q Resume output
        Ctrl-o Discard output
        Ctrl-l Clear screen

 

Transfer: https://blog.csdn.net/dongyanxia1000/article/details/62042065

Guess you like

Origin www.cnblogs.com/gered/p/11526043.html