打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Learning_the_bash_Shell_Third_Edition 16/n

CHAPTER 8

 Process Handling

Process IDs and Job Numbers

UNIX gives all processes numbers, called process IDs, when they are created.

Job Control

Foreground and Background

If you have only one background job running, you can use fg without arguments, and the shell will bring that job into the foreground. But if you have several jobs running in the background, the shell will pick the one that you put into the background most recently. If you want some other job put into the foreground, you need to use the job’s command name, preceded by a percent sign (%), or you can use its job number, also preceded by %, or its process ID without a percent sign. If you don’t remember which jobs are running, you can use the command jobs to list them.

jobs has a few interesting options. jobs -l also lists process IDs:

[1] 93 Running alice &

[2]- 102 Running duchess &

[3] 104 Running hatter &

If you type fg without an argument, the shell will put hatter in the foreground,because it was put in the background most recently. But if you type fg %duchess (or fg %2), duchess will go in the foreground.

You can also refer to the job most recently put in the background by % . Similarly, %-refers to the next-most-recently backgrounded job (duchess in this case). That explains the plus and minus signs in the above: the plus sign shows the most recent job whose status has changed; the minus sign shows the next-most-recently invoked job

 Suspending a Job

 To suspend a job, type CTRL-Z while it is running

You will probably also find it useful to suspend a job and resume it in the background instead of the foreground. You may start a command in the foreground (i.e.,normally) and find that it takes much longer than you expected—for example, a grep, sort, or database query. You need the command to finish, but you would also like control of your terminal back so that you can do other work. If you type CTRL-Z followed by bg, you will move the job to the background.

You can also suspend a job with CTRL-Y. This is slightly different from CTRL-Z in that the process is only stopped when it attempts to read input from the terminal.

 Signals

A signal is a message that one process sends to another when some abnormal event takes place or when it wants the other process to do something. Most of the time, a process sends a signal to a subprocess it created. You’re undoubtedly already comfortable with the idea that one process can communicate with another through an I/O pipeline; think of a signal as another way for processes to communicate with each other. (In fact, any textbook on operating systems will tell you that both are examples of the general concept of interprocess communication, or IPC. * )

Depending on the version of UNIX, there are two or three dozen types of signals,including a few that can be used for whatever purpose a programmer wishes. Signals have numbers (from 1 to the number of signals the system supports) and names;we’ll use the latter. You can get a list of all the signals on your system, by name and number, by typing kill -l. Bear in mind, when you write shell code involving signals,that signal names are more portable to other versions of UNIX than signal numbers.

 Control-Key Signals

  

来源:https://www.icode9.com/content-3-892101.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
读指导文档
python IDLE 背景以及字体的修改
Highlights of Cygwin Functionality
Tom Baeyens's Blog: All you ever wanted to kn...
Background Worker // Pebble Developers
Chrome SandBox 和IE SandBox的比较
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服