TLPI-Chapter 26 监控子进程
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2017. *
* *
* This program is free software. You may use, modify, and redistribute i......
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2017. *
* *
* This program is free software. You may use, modify, and redistribute i......
#define _BSD_SOURCE /* Get on_exit() declaration from <stdlib.h> */
#include <stdlib.h>
#include "tlpi_hdr.h"
static void
atexitFunc1(void)
{
printf("atexit function 1 called\n");
}
static void
atexitFunc2(void)
{
printf("atexit function 2 called\n");
......
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2017. *
* *
* This program is free software. You may use, modify, and redistribute i......
基本概念
信号是事件发生时对进程的通知机制。有时也称为软件中断,信号与硬件中断相似之处在于打断了程序执行的正常流程,大多数情况下,无法预测信号到达的精确时间。
一个具有合适权限的进程能够向另一进程发送信号,信号的这一用法可作为一种同步技术,甚至是进程通信IPC的原始形式。进程也可以向自身发送信号。然而发往进程的诸多信号,通常都是源于内核。
引发内核为进程产生信号的各类事件如下:
硬件发生异常:硬件异常的例子包括执行一条异常的机器语言指令,如被0除,或者引用了无法访问的内存区域。
用户键入能够产生信号的中断特殊字符:包括中断字符(Control-C)
发生了软件事件:例如......
函数:void *memalign(size_t alignment, size_t size);
The obsolete function memalign() allocates size bytes and returns a pointer to the allocated memory. The memory address will be a multiple of alignment, which must be a power of two.
memalign 分配 size 字节的空间,返回指向该空间的指针,空间的地址是 alignment 的倍数,alig......
“The /proc file system exposes a range of kernel information to application programs. Each /proc/PID subdirectory contains files and subdirectories that provide information about the process whose ID matches PID. Various other files and directories under /proc expose system-wide information that pro......
关于系统限制C语言标准和SUSv3提供了两种方法:
1.在编译程序时能够获得一些限制和选项。
2.一些限制在程序运行时可能会发生变化。对此SUSv3定义了3个函数sysconf() pathconf()和fpathconf(),供应用程序调用以检查系统实现的限制和选项。
SUSv3将其规定的限制归为三类:
运行时恒定值 路径名变量值 运行时可增加值
在shell中,可以使用getconf命令获取特定UNIX系统中已然实现的限制和选项。例:
getconf ARG_MAX
getconf NAME_MAX /boot
在运行时获取系统限制#include <unis......
日历时间Calendat Time
UNIX系统内部对时间的表示均是以自1970年1月1日的零点以来的秒数来度量。日历时间存储与类型time_t的变量中,此类型是由SUSv3定义的整数类型。
系统调用gettimeofday(),可于tv指向的缓冲区中返回日历时间。
#include <sys/time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz);
Returns 0 on success, or –1 on error
参数tv是指向如下数据结构的一个指针:
struct timeval {
_......
这一章开始看的有点懵,在网上搜索到一篇文章有助于理解链接地址Set-User-ID
1.每个进程都有一套用数字表示的用户ID和组ID。具体有实际用户ID(real user ID), 实际组ID(real group ID),有效用户ID(effective user ID),有效组ID(effective group ID),保存的set-user-ID和set-group-ID,文件系统用户ID和文件系统组ID,辅助组ID。
将上述种种ID称为进程凭证。
2.实际用户ID和实际组ID:
这两个ID确定了进程所属的用户和组。当用户登录时,会从/etc/passwd文件中读取UID......
课后习题存在错误,在官网勘误表中更正如下:
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <pwd.h>
int
main(int argc, char *argv[])
{
if (argc != 3 || strcmp(argv[1], "--help") == 0) {
fprintf(stderr, "Usage: %s uid1 uid2\n", arg......