ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Learning_the_bash_Shell_Third_Edition 16/n

2021-03-15 15:33:52  阅读:242  来源: 互联网

标签:foreground Shell Third 16 process will also job background


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

 

 

 

 

标签:foreground,Shell,Third,16,process,will,also,job,background
来源: https://www.cnblogs.com/winditsway/p/14537880.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有