ebook15-10

Similar documents
第6章 信号量,中断和时间

linux进程间通信

ebook15-C

上 述 的 描 述 是 在 一 台 计 算 机 上 只 有 一 颗 CPU, 并 且 该 CPU 只 有 一 个 核 心 的 情 形, 在 这 种 环 境 下, 虽 然 系 统 可 以 运 行 多 个 任 务, 但 是 在 某 一 个 时 间 点,CPU 只 能 执 行 一 个 进 程 但 是 如

IntelBook_cn.doc

,,.,. :, :,1999. Barry Wilkinson and Michael Allen. Parallel Programming(Techniques and Applications using Networked Workstations and Parallel

ECF_Signals_and_Nonlocal_Jumps_罗世通

ebook15-2

ebook

C/C++ - 文件IO

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

ebook15-12

华恒家庭网关方案

C/C++ - 函数

新版 明解C言語入門編

untitled

FY.DOC

46 * the current mask in old_mask and block until a signal comes in. 47 */ /* 自动地更换成新的信号屏蔽码, 并等待信号的到来 * * 我们需要对系统调用 (syscall) 做一些处理 我们会从系统调用库接口取得某些信息

ebook15-4

untitled

多进程管理副本.key

ebook8-30

CC213

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

新・明解C言語入門編『索引』

C/C++ - 字符输入输出和字符确认

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

epub 77-2

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

新版 明解C++入門編

新・解きながら学ぶC言語

C/C++ - 字符串与字符串函数

像 客 样 使 命令行 徐 东

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.07.doc

C PICC C++ C++ C C #include<pic.h> C static volatile unsigned char 0x01; static volatile unsigned char 0x02; static volatile unsigned cha

C/C++程序设计 - 字符串与格式化输入/输出

untitled

目 錄 1. 蒸 豬 肉 丸 2. 蜜 汁 腰 果 3. 鳳 梨 蝦 球 4. 金 菇 扒 芥 菜 5. 松 鼠 黃 魚 6. 椒 鹽 魷 魚 7. 時 蔬 燴 蝦 丸 8. 粉 蒸 小 排 骨 9. 酥 炸 黃 魚 條 10. 彩 椒 炒 魷 魚

Microsoft Word - Index.doc

02

C 1

C/C++语言 - 运算符、表达式和语句

1 LINUX IDE Emacs gcc gdb Emacs + gcc + gdb IDE Emacs IDE C Emacs Emacs IDE ICE Integrated Computing Environment Emacs Unix Linux Emacs Emacs Emacs Un

Ps22Pdf

第11章 可调内核参数

日本清酒精妙绝伦的另一面

ebook35-2

C/C++ 语言 - 循环

epub29-1

C语言的应用.PDF

ebook14-4

C/C++语言 - C/C++数据








1

Biotechnology

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)


提纲 1 2 OS Examples for 3

C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

C/C++语言 - 分支结构

, 即 使 是 在 昏 暗 的 灯 光 下, 她 仍 然 可 以 那 么 耀 眼 我 没 有 地 方 去, 你 会 带 着 我 么 杜 晗 像 是 在 嘲 笑 一 般, 嘴 角 的 一 抹 冷 笑 有 着 不 适 合 这 个 年 龄 的 冷 酷 和 无 情, 看 着 江 华 的 眼 神 毫 无 温

<4D F736F F D204C696E7578CFB5CDB3B5F7D3C3C1D0B1ED>


Microsoft PowerPoint - os_4.ppt

_汪_文前新ok[3.1].doc


恩 典 课 堂 教 学 概 览 课 堂 环 节 持 续 时 间 活 动 所 需 材 料 1 欢 迎 持 续 在 门 口 欢 迎 学 生, 聆 听 他 们 分 享 本 周 开 心 或 烦 恼 的 事 预 备 活 动 <10 分 钟 A 猜 猜 是 谁 B 上 帝 的 礼 物 无 孩 子 们 的 儿 时

团 契 就 体 力 来 说, 参 孙 乃 是 地 上 极 强 壮 的 人 ; 但 在 自 制 忠 贞 和 坚 稳 上, 他 却 是 人 间 最 软 弱 的 了 先 祖 与 先 知 第 页 教 室 布 置 见 第 一 课 课 堂 教 学 概 览 课 堂 环 节 持 续 时 间 活 动

ebook35-21

bingdian001.com

static struct file_operations gpio_ctl_fops={ ioctl: gpio_ctl_ioctl, open : gpio_open, release: gpio_release, ; #defineled1_on() (GPBDAT &= ~0x1) #def

C 1 # include <stdio.h> 2 int main ( void ) { 4 int cases, i; 5 long long a, b; 6 scanf ("%d", & cases ); 7 for (i = 0;i < cases ;i ++) 8 { 9

c_cpp

C++ 程式設計

untitled

nooog

C/C++ - 结构体、共用体、枚举体

第7章-并行计算.ppt

云 浮 市 总 工 会 学 习 贯 彻 市 委 五 届 九 次 全 会 精 神 全 省 工 会 第 二 季 度 暨 上 半 年 劳 资 纠 纷 研 判 会 召 开 河 源 市 总 工 会 召 开 劳 资 纠 纷 研 判 会 议 湛 江 市 总 工 会 召 开 上 半 年 劳 资 纠 纷 研 判 会

C

W. Richard Stevens UNIX Sockets API echo Sockets TCP OOB IO C struct C/C++ UNIX fork() select(2)/poll(2)/epoll(4) IO IO CPU 100% libevent UNIX CPU IO

目 錄 摘 要... 1 壹 研 究 動 機... 1 貳 研 究 目 的... 1 參 文 獻 探 討... 1 肆 研 究 設 備 及 材 料... 2 伍 研 究 過 程 及 方 法... 2 陸 研 究 結 果... 6 柒 討 論 捌 結 論 玖 參 考 資 料 及

信 息 披 露 义 务 人 声 明 1 信 息 披 露 义 务 人 依 据 中 华 人 民 共 和 国 公 司 法 中 华 人 民 共 和 国 证 券 法 上 市 公 司 收 购 管 理 办 法 公 开 发 行 证 券 公 司 信 息 披 露 内 容 与 格 式 准 则 第 15 号 权 益 变 动

, (, ),,,,,, : : ( ), :,,,,,,, ( ), ( ),,,,,, ( ) ( ),, :!,,,,,,,,,,,,,,,,,,,,,,, [1 ] :,,,, :, ;, ( ),, :,,,,,,,,,,, 66

untitled

untitled

C

第一章 概论

1

6 C51 ANSI C Turbo C C51 Turbo C C51 C51 C51 C51 C51 C51 C51 C51 C C C51 C51 ANSI C MCS-51 C51 ANSI C C C51 bit Byte bit sbit

untitled

epub 33-8

Microsoft Word - 第三章第一節第二節.doc

untitled

Transcription:

1 0 10.1 U N I X V 7 4. 3 B S D S V R 3 P O S I X. 1 100 % 10.2 S I G S I G A B RT a b o r t S I G A L R M a l a r m V 7 1 5 S V R 4 4. 3 + B S D 31 < s i g n a l. h > 0 10. 9 k i l l 0 P O S I X. 1 D E L E T E S I G I N T 11 0 S I G S E G V k i l l ( 2 ) k i l l ( 1 ) k i l l 0 S I G U R G ( ) S I G P I P E ( ) S I G A L R M ) ( e r r n o )

1 0 1 9 9 (1) S I G K I L L S I G S TO P 0 (2) S I G C H L D w a i t p i d I D S I G T E R M k i l l (3) 10-1 1 0-1 P O S I X. 1 j o b 10-1 UNIX ANSI C P O S I X. 1 S V R 4 4. 3 + B S D S I G A B R T S I G A L R M ( a b o r t ) w / c o r e ( a l a r m ) S I G B U S w / c o r e S I G C H L D S I G C O N T S I G E M T w / c o r e S I G F P E w / c o r e S I G H U P S I G I L L w / c o r e S I G I N F O S I G I N T S I G I O I / O / S I G I O T w / c o r e S I G K I L L S I G P I P E S I G P O L L S I G P R O F S I G P W R ( p o l l ) ( s e t i t i m e r ) / S I G Q U I T w / c o r e S I G S E G V w / c o r e S I G S T O P

2 0 0 U N I X ANSI C P O S I X. 1 S V R 4 4. 3 + B S D S I G S Y S w / c o r e S I G T E R M S I G T R A P w / c o r e S I G T S T P S I G T T I N S I G T T O U t t y t t y S I G U R G S I G U S R 1 S I G U S R 2 S I G V T A L R M ( s e t i t i m e r ) S I G W I N C H S I G X C P U S I G X F S Z C P U ( s e t r l i m i t ) w / c o r e ( s e t r l i m i t ) w / c o r e w / c o r e c o r c o r e U N I X U N I X c o r e c o r ( a ) - - I D ( b ) - - I ( c ) ( d ) ( 7. 11 R L I M I T _ C O R E ) c o r e ( ) c o r e P O S I X. 1 U N I X U N I X 6 ( a ) ( b ) - - I D 4. 3 + B S D c o r e.p ro g p ro g 16 c o r e 1 0-1 U N I X P D P - 11 SIGABRT a b o r t 10. 17 SIGALRM a l a r m 10. 10 s e t i t i m e r ( 2 ) SIGBUS SIGCHLD S I G C H L D w a i t I D

1 0 2 0 1 V S I G C L D ( H ) S V R 2 S I G C H L D 10. 7 SIGCONT v i 10. 20 SIGEMT E M T P D P - 11 emulator trap SIGFPE 0 SIGHUP 9-11 s e s s i o n s _ l e a d e r C L O C A L C L O C A L 11 9-7 ( ) 13 S I G H U P SIGILL 4. 3 B S D a b o r t S I G A B RT SIGINFO 4. 3 + B S D C t r l - T 9-8 SIGINT D E L E T E C t r l - C ( 9-8 ) SIGIO I / O 12. 6. 2 10-1 S I G I O S V R 4 S I G I O S I G P O L L 4. 3 + B S D ( 4. 2 B S D ) SIGIOT I O T P D P - 11 TRAP(input/output TRAP) V a b o r t S I G A B RT SIGKILL

2 0 2 U N I X SIGPIPE 14. 2 SIGPOLL S V R 4 12. 5. 2 p o l l 4. 3 + B S D S I G I O S I G U R G SIGPROF s e t i t i m e r ( 2 ) SIGPWR S V R 4 ( U P S ) U P S 15 3 0 S I G P W R S I G P W R i n i t i n i t V i n i t i n i t t a b p o w e r f a i l p o w e r w a i t U P S R S - 232 SIGQUIT C t r l -\ 9-8 S I G I N T c o r e SIGSEGV S E G V segmentation violation SIGSTOP ( S I G T S T P ) S I G S TO P SIGSYS SIGTERM k i l l ( 1 ) SIGTRAP SIGTSTP P D P - 11 T R A P C t r l - Z SIGTTIN 9. 8 e r r n o E I O ( a ) ( b ) SIGTTOU 9. 8 S I G T T I N 11 S I G T T I N ( a ) ( s t o p ) C t r l - S C t r l - Q

1 0 2 0 3 ( b ) e r r n o E I O t c s e t a t t r, tcsendbreak, tcdrain, tcflush, tcflow t c s e t p g r p 11 SIGURG SIGUSR1 SIGUSR2 SIGVTALRM s e t i t i m e r ( 2 ) SIGWINCH SVR4 4. 3 + B S D i o c t l ( 11. 12 ) i o c t l - S I G W I N C H SIGXCPU SVR4 4. 3 + B S D 7. 11 C P U SIGXFSZ 7. 11 S V R 4 4. 3 + B S D 10.3 signal U N I X s i g n a l #include <signal.h> void (*signal (int s i g n o, void (*f u n c)(int))) (int); S I G _ E R R s i g n a l ANSI C ANSI C I / O U N I X ANSI C 2 P O S I X. 1 15 S V R 4 s i g n a l S V R 2 10. 4 4. 3 + B S D s i g n a l s i g a c t i o n 10. 14 s i g a c t i o n 4. 3 + B S D s i g a c t i o n s i g n a l 10-12 s i g n a l s i g n o 10-1 f u n c ( a ) S I G _ I G N ( b ) S I G _ D F L ( c ) S I G _ I G N S I G K I L L S I G S TO P S I G _ D F L 10-1 signal handler signal-catching function

2 0 4 U N I X s i g n a l ( v o i d ) s i g n o s i g n a l ( ) s i g n a l 10. 21 S V R 4 4. 3 + B S D s i g n a l t y p e d e f Plauger 1992 typedef void Sigfunc(int); s i g n a l Sigfunc *signal(int, Sigfunc *); t y p e d e f o u r h d r. h B <signal.h>, #define SIG_ERR (void (*)())-1 #define SIG_DFL (void (*)())0 #define SIG_IGN (void (*)())1 s i g n a l 1 0 1 U N I X 10-1 10. 10 p a u s e 10-1 S I G U S R 1 S I G U S R 2

1 0 2 0 5 k i l l ( 1 ) U N I X ( k i l l ) k i l l ( 1 ) k i l l ( 2 ) $ a.out & [1] 4720 s h e l l I D $ kill -USR1 4720 S I G U S R 1 received SIGUSR1 $ kill -USR2 4720 S I G U S R 2 received SIGUSR2 $ kill 4720 S I G T E R M [1] + Terminated a.out & S I G T E R M 10.3.1 e x e c e x e s h e l l s h e l l cc main.c & s h e l l int sig_int(), sig_quit(); if (signal(sigint, SIG_IGN)!= SIG_IGN) signal(sigint, sig_int); if (signal(sigquit, SIG_IGN)!= SIG_IGN) signal(sigquit, sig_quit); S I G I N T S I G Q U I T s i g n a l s i g a c t i o n

2 0 6 U N I X 10.3.2 f o r k 10.4 U N I X V 7 4. 2 B S D S V R 3 V P O S I X. 1 B S D ( 10-1 C ANSI C v o i d i n t s i g n a l

1 0 2 0 7 p a u s e s i g _ i n t _ f l a g 0 0 s i g _ i n t _ f l a g p a u s t 10.5 U N I X e r r n o E I N T R pause( ) w a i t i o c t l 14 I / O I / O (

2 0 8 U N I X ) a g a i n : if ( (n = read(fd, buff, BUFFSIZE)) < 0) { if (errno == EINTR) goto again; /* just an interrupted system call */ /* handle other errors */ } 4. 2 B S D i o c t l r e a d r e a d v w r i t e w r i t e v w a i t w a i t p i d w a i t w a i t p i d 4. 3 B S D P O S I X. 1 V S V R 4 s i g a c t i o n 10. 14 S A _ R E S TA RT 4. 3 + B S D 4. 3 B S D s i g v e c P O S I X. 1 s i g a c t i o n S V R 4 s i g a c t i o n S A _ R E S TA RT 4. 2 B S D 1 0-2 10-2 s i g n a l, V7, SVR2, SVR3, SVR4 s i g s e t, s i g h o l d, s i g r e l s e s i g i g n o r e, s i g p a u s e SVR3, SVR4 s i g n a l, s i g v e c, s i g b l o c k 4. 2 B S D s i g s e t m a s k, s i g p a u s e 4.3BSD, 4.3+BSD s i g a c t i o n, s i g p r o c m a s k s i g p e n d i n g, s i g s u s p e n d P O S I X. 1 S V R 4 4. 3 + B S D

1 0 2 0 9 U N I X 10-2 SunOS 4.1.2 s i g a c t i o n S V R 4 4. 3 + B S D 10-12 s i g n a l S I G A L R M 10-13 s i g n a l _ i n t r ( ) 12. 5 s e l e c t p o l l 10.6 e x i t l o n g j m p m a l l o c m a l l o c? g e t p w n a m 6. 2? m a l l o c m a l l o c g e t p w n a m P O S I X. 1 10-3 * P O S I X. 1 SVR4 SVID AT&T 1989 10-3 _ e x i t f o r k p i p e s t a t a b o r t * f s t a t r e a d s y s c o n f a c c e s s g e t e g i d r e n a m e t c d r a i n a l a r m g e t e u i d r m d i r t c f l o w c f g e t i s p e e d g e t g i d s e t g i d t c f l u s h c f g e t o s p e e d g e t g r o u p s s e t p g i d t c g e t a t t r c f s e t i s p e e d g e t p g r p s e t s i d t c g e t p g r p c f s e t o s p e e d g e t p i d s e t u i d t c s e n d b r e a k c h d i r g e t p p i d s i g a c t i o n t c s e t a t t r c h m o d g e t u i d s i g a d d s e t t c s e t p g r p c h o w n k i l l s i g d e l s e t t i m e c l o s e l i n k sigemptyset t i m e s c r e a t l o n g j m p * s i g f i l l s e t u m a s k d u p l s e e k s i g i s m e m b e r u n a m e d u p 2 m k d i r s i g n a l * u n l i n k e x e c l e m k f i f o s i g p e n d i n g u t i m e e x e c v e o p e n s i g p r o c m a s k w a i t e x i t * p a t h c o n f sigsuspend w a i t p i d f c n t l p a u s e s l e e p w r i t e

2 1 0 U N I X 10-3 ( a ) ( b ) m a l l o c f r e e ( c ) I / O I / O 10-3 e r r n o m a i n e r r n o r e a d e r r n o m a i n 10-3 e r r n o ( S I G C H L D w a i t w a i t e r r n o ) P O S I X. 1 10-3 l o n g j m p s i g l o n g j m p 1 0. 15 s i g l o n g j m p s i g l o n g j m p s i g s e t j m p 10-2 m y _ a l a r m getpwnam, m y _ a l a r m 10. 10 a l a r m 10-2 S I G A L R M S I G S E G V c o r e m a i n g e t p w n a m S I G S E G V m a i n g e t p w n a m E B A D F 10-2

1 0 2 1 1 10.7 SIGCLD S I G C L D S I G C H L D S I G C L V S I G C H L D B S D P O S I X. 1 B S D S I G C H L D B S D S I G C H L D w a i t V S I G C L D s i g n a l s i g s e t S RV 3 S V R 4 S I G C L D (1) S I G _ I G N S I G _ D F L 10-1 w a i t w a i t 1 e r r n o E C H I L D ( S I G _ I G N ) P O S I X. 1 S I G C H L D 4. 3 + B S D S I G C H L D S V R 4 s i g n a l s i g s e t S I G C H L D S V R 4 s i g a c t i o n S A _ N O C L D WA I T ( 10-5 ) (2) S I G C L D S I G C L D ( 2 ) 10. 4 s i g n a l 10-3 S V R 2 SIGCLD received s i g n a l ( 2 ) S I G C L D

2 1 2 U N I X s i g n a l w a i t s i g n a l S I G C H L D? POSIX.1 P O S I X. 1 P O S I X. 1 s i g a c t i o n S I G C H L D S I G C H L D #define SIGCHLD S I G C L D 10-3 V S I G C L D

1 0 2 1 3 10.8 0 k i l l g e n e r a t i o n d e l i v e r y p e n d i n g ( a ) ( b ) s i g p e n d i n g 10. 13? P O S I X. 1 U N I X U N I X V S I G C L D 1 0. 7 AT & T 1 9 9 0 e s i g a c t i o n ( 2 ) S A - S I G I N F O 10-5 S V R 4? P O S I X. 1 P O S I X. 1 S I G S E G V s i g p r o c m a s k 10. 12 P O S I X. 1 s i g s e t _ t 10. 11 10.9 kill r a i s e k i l l r a i s e r a i s e ANSI C P O S I X. 1 ANSI C k i l l I D #include <sys/types.h> #include <signal.h> int kill(pid_t p i d, int s i g n o) ;

2 1 4 U N I X int raise(int s i g n o) ; 0 1 k i l l p i d p i d > 0 I D p i d p i d == 0 I D I D U N I X (pid 0) init (pid 1) (pid 2) pid < 0 I D p i d pid == 1 POSIX.1 S V R 4 4. 3 + B S D broadcast signal 4. 3 + B S D I D - - I D I D I D I D _ P O S I X _ S AV E D _ I D S S V R 4 - - I D I D S I G C O N T P O S I X. 1 0 s i g n o k i l l k i l l 1 e r r n o E S R C H U N I X I D I D k i l l k i l s i g n o 10.10 alarm p a u s e a l a r m ( ) S I G A L R M #include <unistd.h> unsigned int alarm(unsigned int s e c o n d s) ; 0

1 0 2 1 5 s e c o n d s s e c o n d S I G A L R M U N I X 1 P O S I X. 1 a l a r m a l a r m s e c o n d s 0 S I G A L R M p a u s e #include <unistd.h> int pause(void); 1 e r r n o E I N T R p a u s e p a u s 1 e r r n o E I N T R a l a r m p a u s e 10-4 s l e e p 1 10-4 sleep s l e e p 1 10. 19 s l e e p

2 1 6 U N I X (1) s l e e p 1 a l a r m a l a r m a l a r s l e e p 1 (2) S I G A L R M s i g n a l (3) a l a r m p a u s e a l a r m p a u s e p a u s s l e e p 10-4 ( 1 ) ( 2 ) ( 3 s e t j m p s i g p r o c m a s k s i g s u s p e n d 1 0. 1 9 S V R 2 s l e e p s e t j m p l o n g j m p ( 7. 10 ) ( 3 ) s l e e p 2 10-5 ( 1 ) ( 2 ) 10-5 sleep 10-4 p a u s e S I G A L R M s l e e p 2 s l e e p 2 S I G A L R M l o n g j m p 10-6 S I G I N T f o r 5 s l e e p 2 j v o l a t i l e

1 0 2 1 7 10-6 $ a. o u t ˆ? sig_int starting sleep2 returned: 0 10-6 s l e e p 2 s l e e p 2 l o n g j m p s i g _ i n t S V R 2 s l e e p 10. 3 s l e e p 1 s l e e p 2 s l e e p a l a r m 10. 5 10-7 10-7 r e a d

2 1 8 U N I X U N I X (1) 10-7 10-4 a l a r m r e a d r e a d 1 (2) S I G A L R M r e a d P O S I X. 1 l o n g j m p ( 10-8 ) 10-8 l o n g j m p r e a d

1 0 2 1 9 10-5 I / O l o n g j m p s e l e c t p o l l 12. 5. 1 12. 5. 2 1 0. 11 signal set s i g p r o c m a s k P O S I X. 1 s i g s e t _ t #include <signal.h> int sigemptyset(sigset_t s e t) *; int sigfillset(sigset_t s e t) *; int sigaddset(sigset_t s e t, * int s i g n o) ; int sigdelset(sigset_t s e t, * int s i g n o) ; 0 1 int sigismember(const sigset_t s e t, * int s i g n o) ; 1 0 s i g e m p t y s e t s e t s i g f i l l s e s e s i g e m p t y s e t s i g f i l l s e t C 0 s i g a d d s e t s i g d e l s e t

2 2 0 U N I X 4. 3 + B S D 31 32 s i g e m p t y s e t s i g f i l l s e t < s i g n a l. h > #define sigemptyset(ptr) ( *(ptr) = 0) #define sigfillset(ptr) ( *(ptr) = (sigset_t)0, 0 ) s i g f i l l s e t 0 s i g a d d s e t s i g d e l s e t s i g i s m e m b e r 0 1 10-9 10-9 sigaddset s i g d e l s e t s i g i s m e m b e r < s i g n a l. h > P O S I X. 1 e r r n o 10.12 sigprocmask 10. 8 s i g p r o c m a s k ( )

1 0 2 2 1 # include <signal.h> int sigprocmask(int h o w, const sigset_t s e * t, sigset_t o * s e t) ; 0 1 o s e t o s e s e t h o w 10-4 h o S I G _ B L O C K S I G _ S E T M A S K 10-4 s i g p r o c m a s k h o w S I G _ B L O C K S I G _ U N B L O C K S I G _ S E T M A S K s e t s e s e t s e s e t s e t h o w s i g p r o c m a s k s i g p r o c m a s 10-10 - 14 10-15 10-1 1 0. 9 10-10

2 2 2 U N I X 10.13 sigpending s i g p e n d i n g s e t #include <signal.h> int sigpending(sigset_t s e t) *; 0 1 10-11 S I G Q U I T 5 5 S I G Q U I T S I G Q U I T S I G _ S E T M A S K S I G _ U N B L O C K S I G _ U N B L O C K S I G _ S E T M A S K 10. 18 s y s t e m s i g p r o c m a s k S I G Q U I T s i g _ q u i t p r i n t f s i g p r o c m a s k p r i n t f 10-11 s i g p r o c m a s k

1 0 2 2 3 5 C t r l - \ Q U I T ( c o r e d u m p ) S I G Q U I T c o r e ( s h e l l ) $ a. o u t ˆ \ SIGQUIT pending caught SIGQUIT SIGQUIT unblocked ˆ \ Q u i t ( c o r e d u m p ) ( 5 ) s l e e p s i g p r o c m a s k $ a. o u t \ ˆ 10 ( 5 ) SIGQUIT pending caught SIGQUIT SIGQUIT unblocked ˆ \ Q u i t ( c o r e d u m p ) S I G Q U I T 10 S I G Q U I T 10.14 sigaction s i g a c t i o n ( ) U N I X s i g n a l s i g a c t i o n s i g n a l #include <signal.h> int sigaction(int s i g n o, const struct sigaction a c t, * struct sigaction o a * c t) ; 0-1

2 2 4 U N I X s i g n o a c t o a c t struct sigaction { void (*sa_handler)(); /* addr of signal handler, or SIG_IGN, or SIG_DFL */ sigset_t sa_mask; /* additional signals to block */ int sa_flags; /* signal options, Table 10-5 */ } ; s a _ h a n d l e r ( S I G _ I G N S I G _ D F L ) s a _ m a s k 10. 8 s i g a c t i o n P O S I X. 1 a c t s a _ f l a g s 10-5 10-5 ( s a _ f l a g s ) P O S I X. 1 S V R 4 4. 3 + B S D S A _ N O C L D S T O P s i g n o S I G C H L D SVR4 SA_NOCLDWA I T S A _ R E S T A R T 10. 5 S A _ O N S T A C K s i g a l t s t a c k ( 2 ) S A _ N O C L D W A I T s i g n o S I G C H L D w a i t - 1 e r r n o E C H I L D 10. 7 S A _ N O D E F E R S A _ R E S E T H A N D S I G _ D F L S A _ S I G I N F O 1 0. 2 1

1 0 2 2 5 s i g n a l s i g a c t i o n s i g n a l 4. 3 + B S D ( P O S I X. 1 P O S I X ) S V R 4 s i g n a l S V R 4 s i g n a l s i g a c t i o n ( S V R 4 s i g a c t i o n S A _ R E S E T H A N D S A _ N O D E F E R s i g n a l s i g n a l 10-12 10-12 s i g a c t i o n s i g n a l s i g e m p t y s e t a c t act.sa_mask = 0; S I G A L R M S A _ R E S TA RT S I G A L R M I / O 10-7 S u n O S S A _ I N T E R R U P T s i g n a l _ i n t r 10-13 s i g n a l 10-13 signal_intr

2 2 6 U N I X S A _ I N T E R R U P T s a _ f l a g s 10.15 sigsetjmp s i g l o n g j m p 7. 10 s e t j m p l o n g j m p l o n g j m p ANSI C a b o r t e x i t l o n g j m p 10-5 1 0-8 l o n g j m p l o n g j m p? 4. 3 + B S D s e t j m p l o n g j m p S V R 4 4. 3 + B S D _ s e t j m p _ l o n g j m p P O S I X. 1 s e t j m p l o n g j m p s i g s e t j m p s i g l o n g j m p #include <setjmp.h> int sigsetjmp(sigjmp_buf e n v, int s a v e m a s k) ; void siglongjmp(sigjmp_buf e n v, int val) 0 s i g l o n g j m p 0 s e t j m p l o n g j m p s i g s e t j m p s a v e m a s k 0 s i g s e t j m p e n v s i g l o n g j m p 0 s a v e m a s k s i g s e t j m p e n v, s i g l o n g j m p 10-14 s i g s e t j m p s i g l o n g j m p

1 0 2 2 7 10-14 s i g s e t j m p s i g l o n g j m p s i g l o n g j m p s i g s e t j m p c a n j u m p 0 s i g l o n g j m p j m p b u f ( ) s i g s e t j m p s i g l o n g j m p s i g l o n g j m p

2 2 8 U N I X C l o n g j m p s i g _ a t o m i c _ t ANSI C A N S I v o l a t i l e m a i n 1 0-1 10 - ( m a i n ) ( s i g _ u s r 1 ) ( s i g _ a l r m ) 0 ( ) S I G U S R 1 S I G U S R 1 S I G A L R M 10-1 10-14 $ a.out & starting main: [1] 531 s h e l l I D $ kill -USR1 531 S I G U S R 1 starting sig_usr1: SIGUSR1 $ in sig_alrm: SIGUSR1 SIGALRM finishing sig_usr1: SIGUSR1 ending main: [1] + Done a.out & s i g l o n g j m p s i g s e t j m p

1 0 2 2 9 10-14 s i g s e t j m p s i g l o n g j m p _ s e t j m p _ l o n g j m p 4. 3 + B S D ending main: SIGUSR1 _ s e t j m p m a i n S I G U S R 1 10.16 sigsuspend p a u s e? S I G I N T S I G I N T p a u s e S I G I N T s i g s u s p e n d #include <signal.h> int sigsuspend(const sigset_t s i g m * a s k) ; 1, errno E I N T R s i g m a s k s i g s u s p e n d s i g s u s p e n 1 e r r n o E I N T R ( ) 10-15 10-15

2 3 0 U N I X s i g s u s p e n d S I G I N T ( o l d m a s k ) 10-15 $ a. o u t in critical region: SIGINT ˆ? in sig_int: SIGINT after return from sigsuspend: SIGINT s i g s u s p e n d s i g s u s p e n d 10-16 m a i n

1 0 2 3 1 $ a. o u t ˆ? i n t e r r u p t ˆ? i n t e r r u p t ˆ? i n t e r r u p t ˆ\ $ ANSI C P O S I X P O S I X s i g _ a t o m i c _ t P O S I X. 1 10-3 P O S I X 10-16 s i g s u s p e n d

2 3 2 U N I X 10-17 8. 8 T E L L _ WA I T T E L L _ PA R E N T T E L L _ C H I L D WA I T _ PA R E N T WA I T _ C H I L D S I G U S R 1 S I G U S R 2 14-3 10-17

1 0 2 3 3 s i g s u s p e n d ( )? 17-13 S I G I N T S I G A L R M s i g n a l - i n t r s e l e c t ( 1 2. 5. 1 ) S I G A L R M s e l e c t s e l e c t i f s e l e c t s e l e c t ( ) (1) S I G I N T S I G A L R M (2) (3) s e l e c t ( r e a d )

2 3 4 U N I X s i g s u s p e n d ( 3 ) p a u s e 10.17 abort a b o r t #include <stdlib.h> void abort(void); S I G A B RT ANSI C a b o r t e x i t _ e x i t l o n g j m p s i g l o n g j m p ( 10. 15 l o n g j m p s i g l o n g j m p P O S I X. 1 a b o r t S I G A B RT P O S I X. 1 a b o r t ANSI C 5. 13 ) P O S I X. 1 a b o r t I / O f c l o s e a b o r t V a b o r t S I G I O T a b o r t 4. 3 B S D S I G I L L SIG_DFL ( c o r e ) S V R 4 I / O 4. 3 + B S D I / O a b o r t e r r _ d u m p B UNIX tmpfile( ) u n l i n k ANSI C 10-18 P O S I X. 1 a b o r t I / O I / O f c l o s e I / O _ e x i t I / O _ e x i t 10. 9 k i l l 10-18 k i l l

1 0 2 3 5 k i l l 10-18 abort P O S I X. 1 10.18 system 8. 12 s y s t e m P O S I X. 2 s y s t e m S I G I N T S I G Q U I T S I G C H L D 10-19 8. 12 s y s t e m e d ( 1 ) ( e d U N I X s h e l l e d )

2 3 6 U N I X 10-19 s y e t e m e d 10-19 S I G I N T S I G C H L D $ a. o u t a Here is one line of text and another 1 $ p Here is one line of text and another w temp.foo 1 1 37 3 7 q caught SIGCHLD ( a. o u t ) S I G C H L D s i g - c h i d S I G C H L D s y s t e m P O S I X. 2 s y s t e m s y s t e m $ a. o u t

1 0 2 3 7 a hello, world. 1 $ p 1 hello, world w etmp.foo 13 13 ˆ?? caught SIGINT q caught SIGCHLD 9. 6 10-2 s h e l l 10-2 10-19 S I G I N T s h e l l a. o u t e d s y s t e m ( e d ) s y s t e m e d ) s y s t e s y s t e m P O S I X. 2 s y s t e m 10-20 s y s t e m 10-20 ystem P O S I X. 2

2 3 8 U N I X if ( (pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) { /* child */ e x e c l ( ) _ e x i t ( 127 ); } /* parent */ old_intr = signal(sigint, SIG_IGN); old_quit = signal(sigquit, SIG_IGN); waitpid(pid, &status, 0) signal(sigint, old_intr); signal(sigquit, old_quit); f o r k 10-20 f o r k

1 0 2 3 9 e x e c l e x e c l s y s t e m s y s t e m s h e l l 8-13 d a t e 0 s h e l l exit 44 44? 8-14 $ tsys "sleep 30" ˆ?normal termination, exit status = 130 $ tsys "sleep 30" ˆ \ s h: 946 Quit normal termination, exit status = 131 s l e e p p r _ e x i t 8-3 s l e e p 130 1 31? Bourne shell 128 s h e l l $ s h Bourne shell $ sh -c "sleep 30" ˆ? $ echo $? 130 $ sh -c "sleep 30 " ˆ \sh:962 Quit-core dumped $ echo $? 131 $ e x i t Bourne shell S I G I N T 2 S I G Q U I T 3 s h e l l 130 1 31 s h e l l s y s t e m $ tsys "sleep 30" & [1] 980 $ p s I D PID TT STAT TIME COMMAND 980 p3 S 0:00 tsys sleep 30 981 p3 S 0:00 sh -c sleep 30 982 p3 S 0:00 sleep 30 985 p3 R 0:00 ps $ kill -KILL 981 s h e l l abnormal termination, signal number = 9 [1] + Done tsys "sleep 30" & s h e l l s y s t e m s y s t e m f o r k e x e c w a i t s y s t e m

2 4 0 U N I X 10.19 sleep s h e e p 10-4 1 0-5 s l e e p #include <unistd.h> unsigned int sleep(unsigned int s e c o n d s) ; 0 (1) s e c o n d s (2) a l a r m ( 1 ) 0 s l e e p ( 2 ) ( ) s l e e p a l a r m 10. 10 a l a r m P O S I X. 1 a l a r m ( 10 ) 3 s l e e p ( 5 )? sleep 5 ) 2 S I G A L R M? S V R 4 a l a r m s l e e p s l e e p ( 3 ) s l e e p 2 s l e e p 0 s l e e p S I G A L R M alarm(6), 3 s l e e p ( 5 ) 3 s l e e p 5 s l e e p 2 4. 3 + B S D s e t i t i m e r ( 2 ) a l a r m s l e e p ( a l a r m ) ( s e t i t i m e r ) S I G A L R M s l e e p a l a r m s l e e p s l e e p s l e e p s l e e p 4. 3 + B S D 10-21 POSIX.1 sleep 10-4 P O S I X. 1

1 0 2 4 1 10-21 sleep 10-4 s l e e p 10-21 10-5 a l a r m p a u s e S I G A L R M 10.20 10-1 P O S I X. 1 SIGCHLD SIGCONT SIGSTOP SIGTSTP SIGTTIN

2 4 2 U N I X SIGTTOU P O S I X. 1 S I G C H L D U N I X s h e l l C t r l - Z S I G T S T P s h e l l s h e l l S I G C O N T S I G T T I N S I G T TO U s h e l l v i ( 1 ) v i v i ( S I G T S T P S I G S TO P S I G T T I N S I G T TO U S I G C O N T S I G C O N T S I G C O N T S I G C O N T 10-22 10-22 S I G T S T P S I G _ D F L s h e l l ( / b i n / s h ) S I G _ I G N s h e l l i n i t S I G T S T P S I G T T I N S I G T TO U S I G _ I G N s h e l l s h e l l S I G _ D F L S I G T S T P S I G T S T P ( ) S I G T S T P S I G T S T P f g s h e l l S I G C O N T S I G C O N T k i l l S I G T S T P 1 8

1 0 2 4 3 10-22 S I G T S T P 10.21 10.21.1 extern char *sys_siglist

2 4 4 U N I X p s i g n a l #include <signal.h> void psignal(int s i g n o, const char.*m s g) ; m s g ( ) S V R 4 4. 3 + B S D s y s _ s i g l i s t p s i g n a l 10.21.2 SVR4 s i g a c t i o n s a _ f l a g s SA_SIGINFO ( 10-5 ) s i g i n f o ( ) S I G F P E s i _ c o d e F P E _ I N T D I V 0 F P E _ F LT D I V 0 s i _ c o d e 0 k i l l ( 2 ) s i _ p i d s i _ u i d SVR4 siginfo(5) 10.21.3 4.3+BSD 4. 3 + B S D handler(int s i g n o, int c o d e, struct sigcontext s c p) * ; s i g n o c o d e S I G F P E c o d F P E _ I N T D I V _ T R A P 0 s c p 10.22 U N I X U N I X P O S I X. 1 a b o r t s y s t e m s l e e p P O S I X. 1 10.1 10-1 for ( ; ; )

1 0 2 4 5 10.2 r a i s e 10.3 10-6 10.4 10-8 s e t j m p l o n g j m p I / O signal(sigalrm, sig_alrm); alarm(60) ; if (setjmp (env_alrm)!= 0) { /* handle time out */... }... 10.5 ( a l a r m s e t i t i m e r ) 10.6 10-17 0 f o r k ( ) 1 10.7 10-8 S I G A B RT _ e x i t k i l l 10. 8 S V R 4 s i g i n f o 10. 21 s i _ u i d I D I D 10. 9 10-10 - 1 10.10 s l e e p ( 60 ) 5 ( 5 ) t m _ s e c B S D c r o n 10. 11 3-3 ( a ) B U F F S I Z E 100 ( b ) s i g n a l _ i n t r S I G X F S Z ( c ) w r i t e R L I M I T _ F S I Z E 7. 11 1024 ( s h e l l s e t r l i m i t ) 1024 10.12 f w r i t e ( ) f w r i t a l a r m f w r i t e