1.9信号
当发生某种事件时通知进程,并由进程做相应处理的信息
进程处理信号的三种方法:
忽略该信号
按系统默认方式处理
提供一个函数,信号发生时调用该函数
键盘上有两个产生信号的方法:中断键:ctrl+c 退出键 ctrl+\
-
[root@node3 apue.2e]# cat fig1.10
-
#include "apue.h"
-
#include <sys/wait.h>
-
-
static void sig_int(int); /* our signal-catching function */
-
-
int
-
main(void)
-
{
-
char buf[MAXLINE]; /* from apue.h */
-
pid_t pid;
-
int status;
-
-
if (signal(SIGINT, sig_int) == SIG_ERR) #当发生中断信号时,调用sig_int函数
-
err_sys("signal error");
-
-
printf("%% "); /* print prompt (printf requires %% to print %) */
-
while (fgets(buf, MAXLINE, stdin) != NULL) {
-
if (buf[strlen(buf) - 1] == '\n')
-
buf[strlen(buf) - 1] = 0; /* replace newline with null */
-
-
if ((pid = fork()) < 0) {
-
err_sys("fork error");
-
} else if (pid == 0) { /* child */
-
execlp(buf, buf, (char *)0);
-
err_ret("couldn't execute: %s", buf);
-
exit(127);
-
}
-
-
/* parent */
-
if ((pid = waitpid(pid, &status, 0)) < 0)
-
err_sys("waitpid error");
-
printf("%% ");
-
}
-
exit(0);
-
}
-
-
void
-
sig_int(int signo)
-
{
-
printf("interrupt\n%% ");
-
}
-
[root@node3 apue.2e]# mv fig1.10 fig1.10.c
-
[root@node3 apue.2e]# gcc fig1.10.c
-
[root@node3 apue.2e]# ./a.out
-
% interrupt
-
% [root@node3 apue.2e]#
1.10时间值
日历时间:自1970年1月1日00:00:00以来(国际标准时间)所经过的秒数累计值
进程时间:又称为CPU时间,用户CPU时间+系统CPU时间=CPU时间
用户CPU时间:是执行用户指令所用的时间
系统CPU时间:内核为执行该进程,内核程序所经历的时间
时钟时间:从该进程刚刚开始执行到该进程执行完毕的总时间。
一般情况下,时钟时间>用户CPU时间+系统CPU时间
-
[root@node3 apue.2e]# time -p find /usr/include/ -name "*.h" -print
-
...
-
real 7.27
-
user 0.05
-
sys 0.31
1.11系统调用和库函数
1.12小结
阅读(959) | 评论(0) | 转发(0) |