Foreground background Process Conversion issues

Source: Internet
Author: User

Foreground and background of the process

In Linux there are programs in the foreground and background switch issues, the foreground execution will occupy the terminal, can not be released such as ping command. Such commands can be executed in the background, and the foreground can continue to perform other operations.

Look at this ping command.

[Email protected] ~]# ping 127.0.0.1PING 127.0.0.1 (127.0.0.1) (+) bytes of data.64 bytes from 127.0.0.1:icmp_seq=1 t tl=64 time=0.181 ms64 bytes from 127.0.0.1:icmp_seq=2 ttl=64 time=0.091 MSLs-bytes from 127.0.0.1:icmp_seq= 3 ttl=64 time=0.088 ms64 bytes from 127.0.0.1:icmp_seq=4 ttl=64 time=0.094 ms

I entered LS in the process of pinging, but nothing is output so this is the foreground in the ping process in the use of foreground resources, LS is not output. and add a & after the command, the command will be executed in the background, but will be displayed in the foreground.

[Email protected] ~]# PING 127.0.0.1 (127.0.0.1), bytes of data.64 bytes from 127.0.0.1:icmp_seq=1 ttl=64 time=0.2 Mspwd64 bytes from 127.0.0.1:icmp_seq=2 ttl=64 time=0.087 ms/root

I executed the PWD in the ping process above this time. However, the ping command is also executing, and it is not very comfortable to see the command wrapping without affecting the input. Said so much, do not know to find the problem is not ... How does this affect the ping command to send a cancellation instruction?

This is the problem, want to stop ping my method is to Ps-ef|grep "ping" and then use kill-9 to follow the process number to kill the process on the line

[[email protected] ~]# ps-ef |grep pingroot 27389 26574 0 13:20 pts/3 00:00:00 ping 127.0.0.1root 27391 2 7317 0 13:20 pts/5 00:00:00 grep--color=auto ping[[email protected] ~]# kill-9 27389

Processes running in the background also have process numbers to view the jobs

[Email protected] ~]# PING 127.1 (127.0.0.1), bytes of data.64 bytes from 127.0.0.1:icmp_seq=1 ttl=64 time=0.073 m  S64 bytes from 127.0.0.1:icmp_seq=2 ttl=64 time=0.084 msjo64 bytes from 127.0.0.1:icmp_seq=3 ttl=64 time=0.065 msbs[1]+ Running Ping 127.1 &

The above code does not stop because the background process is running, so the standard input will be wrong line. When I enter jobs, it appears that the running line is the process number in parentheses. Now it is time to mention another command, FG space to follow the process number can be back to the foreground, then CTRL + C can also terminate the ping command.

[[email protected] ~]# ping 127.0.0.1 &64 bytes from 127.0.0.1:  icmp_seq=3 ttl=64 time=0.085 ms64 bytes from 127.0.0.1: icmp_seq=4  ttl=64 time=0.094 msjobs64 bytes from 127.0.0.1: icmp_seq=5 ttl=64  time=0.093 ms                                                        64 bytes from 127.0.0.1: icmp_seq=6 ttl=64 time=0.09664  Bytes from 127.0.0.1: icmp_seq=7 ttl=64 time=0.095 ms64 bytes from  127.0.0.1: icmp_seq=8 ttl=64 time=0.094 ms[1]+  Running         &Nbsp;        ping 127.0.0.1 &64 bytes from  127.0.0.1: icmp_seq=9 ttl=64 time=0.089 msfg 1ping 127.0.0.164 bytes  from 127.0.0.1: icmp_seq=10 ttl=64 time=0.086 ms^c--- 127.0.0.1 ping  statistics ---10 packets transmitted, 10 received, 0% packet  loss, time 9000msrtt min/avg/max/mdev = 0.085/0.100/0.189/0.032 ms[[email  protected] ~]#

Although it performs background runs, it can still be recalled to the foreground.

here is a picture, if there is a similar. All right, I'm searching. 650) this.width=650; "title=" {5j_$l) X) r%rru%uc5{}22.png "src=" https://s4.51cto.com/wyfs02/M01/A4/EE/ Wkiol1m00emd11bqaabihdqyshs533.png "alt=" Wkiol1m00emd11bqaabihdqyshs533.png "/>

Look at the picture to speak, the front desk running direct shortcut keys can sleep in the background.

Want to direct backstage, is command after &

Background hibernation BG Plus process number directly activated, background run (there is a space in the middle of the command)

In both cases, FG can be used to transfer to the foreground.

And also! Jobs view the process number in the background (there may not be a single process)


How to let the background run process into hibernation?

There is a signal in the KILL command this usage, corresponding to the number plus process can modify the state or kill the process, here (kill-19 process number) is the background run to hibernate. What the other numbers mean is no longer explained here.


This article is from the "Mlon Guest" blog, please be sure to keep this source http://13154101.blog.51cto.com/13144101/1964095

Foreground background Process Conversion issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.