Linux operating system program foreground background switching

  

Linux program foreground background switch 1. When running the command on the Linux terminal, add the & symbol at the end of the command to let the program run Ubuntu$">root@Ubuntu$ ./tcpserv01 & Br>

2. If the program is running in the foreground, you can use the Ctrl+z option to pause the program, then use the bg %[number] command to put the program in the background and run Ubuntu">cat@Ubuntu:~/unp/Unpv13e/tcpcliserv$ ./tcpserv01 ^Z [1]+ Stopped ./tcpserv01 cat@Ubuntu:~/unp/unpv13e/tcpcliserv$ bg %1 [1]+ ./tcpserv01 & cat@Ubuntu:~/unp/unpv13e /tcpcliserv$

3. For all running programs, we can use the jobs –l command to view cat@Ubuntu:~/unp/unpv13e/tcpcliserv$ jobs -l [1]+ 4524 Running ./tcpserv01 &

4, you can also use the fg %[number] command to drop a program to the foreground to run cat@Ubuntu:~/unp/unpv13e/tcpcliserv$ fg %1 ./tcpserv01

5, you can also directly terminate the program running in the background, use the kill command cat@Ubuntu: ~/unp/unpv13e/tcpcliserv$ kill %1

Shell support role control, there are the following commands: 1. command& Let the process run in the background 2. jobs View the background running process 3. fg %n Let the background running process n to the foreground 4. bg %n Let the process n to the background Go; PS:"n" The process number that was viewed for the jobs.

B. The following transfer: http://blog.chinaunix.net/u/1604/showart_1079559.html fg, bg, jobs, & ctrl + z are related to system tasks, although now Basically, I don't need to use these commands, but it is also very practical to learn. & Most often used to use this at the end of a command, you can put this command into the background to execute two. Ctrl + z can put a command that is being executed in the foreground into the background and pause three. Jobs to see how many commands are currently running in the background. Fg will transfer the commands in the background to the foreground and continue to run. If there are multiple commands in the background, you can use fg %jobnumber to call the selected command. %jobnumber is the serial number of the command being executed in the background through the jobs command (not pid )

Five. Bg will suspend a command in the background to continue execution. If there are multiple commands in the background, you can use bg %jobnumber to call the selected command. %jobnumber is the serial number of the command being executed in the background (also found by the jobs command). Not pid)

#Linux Use the Shell command to control the task Jobs to execute the following commands can be used to manipulate process tasks: ps lists the running processes in the system; kill sends signals to one or more processes (usually used To kill a process); jobs lists the status of tasks that have been started in the current shell environment. If jobsid is not specified, all active task status information is displayed; if a task is terminated (ie the status of the task is marked as Terminated) ), the shell deletes the process ID of the task from the list known to the current shell environment; bg moves the process to the background (Background); fg moves the process to the foreground (Foreground); transfers the job to the background if you often Working under X graphics, you may have experienced this: run a GUI program through a terminal command, the GUI interface comes out, but your terminal is still in the original You can not continue with other commands in the shell, unless you turn off the GUI program.

In order to make the terminal continue to accept commands after the program is executed, you can move the process to the background and run the program with the following command: #assuming you want to run xmms $xmms & this way, after opening xmms, the terminal prompts It’s back. Now xmms is running in the background; but if you forget to use “&” when you run the program, you don't want to re-execute; you can use ctrl+z to suspend the program, then type bg, so the program is The background continues to run.

Concept: If the current task has 2 task numbers in the background, [1], [2]; if the first background task is successfully executed and the second background task is still being executed, the current The task will automatically become the background task of the background task number “[2]”. So one can point out that the current task will change. When the user enters the commands such as “fg”, “bg” and “stop”, if no quotes are added, the changes are the current tasks.

View Jobs Use the jobs or ps command to see the results of the jobs that are being executed. The job command is executed. The + indicates that it is a current job. The minus table is a job after the current job. jobs -l The option displays the PID of all tasks. The status of jobs can be running, stopped, Terminated, but if the task is killed, the shell deletes the process ID of the task from the list known by the current shell environment; that is, The jobs command displays the task information that is running or suspended in the background in the current shell environment; the hang of the process hangs the background process: execute the stop command in solaris, and view the job number through the jobs command (assumed to be Num), then execute stop %num; in redhat, there is no stop command, you can suspend the process by executing the command kill -stop PID; when you want to re-execute the currently suspended task, you can use bg %num Change the state of the suspended job from stopped to running, and still execute in the background; when it needs to be executed in the foreground, execute the command fg %num; the foreground process hangs: ctrl+Z; Terminate the termination of the background process: Method 1: Use the jobs command to view the job number (assumed to be num), and then execute kill %num method two: use the ps command to view the job number of the job (PID, assuming pid), and then execute the kill pid foreground The termination of the process: ctrl + c kill other role kill in addition to the process can terminate, but also send other signals to the process, use kill -l can see the kill support signal.

SIGTERM is a signal sent by kill when there is no parameter, meaning that the process is terminated, but it depends on whether the process supports it. If the process has not terminated, you can use kill -SIGKILL pid, which is terminated by the kernel, the process can not listen to this signal.

Copyright © Windows knowledge All Rights Reserved