APUE
文章平均质量分 61
duyiwuer2009
这个作者很懒,什么都没留下…
展开
-
APUE-1.3 用标准I/O将标准输入复制到标准输出
/* 1-3 用标准I/O将标准输入复制到标准输出 *//* 该题有助于理解输入输出缓冲区的概念 《APUE》P7*/#include #include #include int main(void){ char ch; while( (ch = fgetc(stdin)) != EOF ) { if( (fputc(ch, stdout)) == EOF ) {原创 2011-11-22 20:23:30 · 610 阅读 · 0 评论 -
getaddrinfo(),gethostbyname(),getnetbyaddr(),getservbyname(),getprotobyname()对比总结
1. gethostbyname()原理:查询 /etc/hosts 等文件及 DNS or NIS 服务器The domain name queries carried out by gethostbyname() and gethostbyaddr() use a combination of any or all of the name server named(8), a b原创 2012-09-22 21:55:06 · 2645 阅读 · 0 评论 -
获取网络号、网络名——getnetent(),getnetbyaddr(),getnetbyname()
struct netent *getnetent(void);struct netent *getnetbyname(const char *name);struct netent *getnetbyaddr(uint32_t net, int type);void setnetent(int stayopen);void endnetent(void);/* Description原创 2012-08-15 21:39:45 · 4655 阅读 · 0 评论 -
调用exec()后进程在何处终止
调用exec()后进程在何处终止#include #include #include #include int main(){ int a = 1; int pid; char buff[] = "before fork"; if(write(1, buff, sizeof(buff) - 1) != (sizeof(buff) - 1)) { perror("wr原创 2012-09-24 10:13:05 · 1436 阅读 · 0 评论 -
编写守护进程
[1] Clear file creation mask. The file mode creation mask that's inherited could be set to deny certain permissions.If the daemon process is going to create files, it may want to set specific perm原创 2012-09-16 19:31:29 · 912 阅读 · 0 评论 -
fork()引起的printf()输出多次的问题
#include #include #include #include int main(){ pid_t pid; printf("before fork - with line break\n"); printf("before fork - no line break"); //fflush(stdout); if( (pid = fork()) < 0 ) {原创 2012-09-26 12:18:14 · 3136 阅读 · 0 评论 -
进程组、会话、控制终端
process group - 进程组session - 会话controlling terminal - 控制终端#include #include #include #include #include #include #include intmain(){ int i, fd0, fd1, fd2; pid_t pid; struct原创 2012-09-16 15:17:12 · 964 阅读 · 0 评论 -
获取协议名、协议号——getprotoent(),getprotobyname(),getprotobynumber()
/* Description of data base entry for a single service. */struct protoent{ char *p_name; /* Official protocol name. */ char **p_aliases; /* Alias list. */ int p_proto; /* Protocol numb原创 2012-08-16 10:21:59 · 4089 阅读 · 0 评论 -
调用 fork 两次避免僵尸进程
Avoid zombie processes by calling fork twice/* * Avoid zombie processes by calling fork twice. * APUE-2e 程序清单8-5 */#include #include #include #include #include "sig_wait_proc.h"int main(原创 2012-09-05 20:19:38 · 4999 阅读 · 2 评论 -
获取主机名、IP——gethostent(),gethostbyname(),gethostbyaddr()
1、原理:查询 /etc/hosts 等文件及 DNS or NIS 服务器The domain name queries carried out by gethostbyname() and gethostbyaddr() use a combination of any or all of the name server named(8), a broken out line fro原创 2012-08-13 21:21:20 · 8649 阅读 · 1 评论 -
APUE-1.2 将标准输入复制到标准输出(read(),write())
/* 1-2 将标准输入复制到标准输出(read(),write()) *//* read(),write(),perror()*/#include #include /* perror() */#include /* perror() */#include /* exit() */#define BUFFSIZE 4096int main(){ int n; ch原创 2011-11-22 20:21:38 · 619 阅读 · 0 评论 -
dup,dup2实现stdout重定向
/* dup,dup2实现stdout重定向 */#include #include #include #include #include #include int main(void){ int fd, tempfd; char buf[] = "Am I in the stdout or in the file?\n"; if( (fd = open("tempfile"原创 2011-11-22 20:30:09 · 3743 阅读 · 0 评论 -
APUE-3.4 对于指定的描述符打印文件标志
/* 3-4 对于指定的描述符打印文件标志 */#include #include #include #include #include int main(int argc, char *argv[]){ int val; if(argc != 2) { printf("usage: a.out \n"); exit(1); } if( (val = fcntl(a原创 2011-11-22 20:29:23 · 951 阅读 · 0 评论 -
APUE-3.2 创建一个具有空洞的文件
/* 3-2 创建一个具有空洞的文件 */#include #include #include /* S_IRUSR,etc.*/#include #include #include int main(void){ char buf1[] = "abcdefghij"; char buf2[] = "ABCDEFGHIJ"; int fd; if( (fd = open(原创 2011-11-22 20:27:23 · 733 阅读 · 0 评论 -
APUE-3.1 测试能否对标准输入设置偏移量(测试stdin,重定向文件,管道,FIFO)
/* 3-1 测试能否对标准输入设置偏移量(测试stdin,重定向文件,管道,FIFO) */#include #include #include #include int main(){ if(lseek(STDIN_FILENO, 0, SEEK_CUR) == -1) { perror("cannot seek"); exit(1); } else { pr原创 2011-11-22 20:26:00 · 858 阅读 · 0 评论 -
信号实现等待另一个进程
wait for another process implemented by signal-----sig_wait_proc.h#ifndef _SIG_WAIT_PROC_H#define _SIG_WAIT_PROC_Hextern void init_wait();extern void wait_proc();extern void tell_proc(pid_t原创 2012-09-05 20:15:10 · 1827 阅读 · 0 评论 -
fork()的一些细节
1、哪些段会被复制The child gets a copy of the parent's data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the原创 2012-09-26 20:17:09 · 1585 阅读 · 0 评论 -
获取服务名、服务端口号、服务所用协议——getservent(),getservbyname(),getservbyport()
Services are represented by the port number portion of the address. Each service is offered on a unique, well-known port number. We can map a service name to a port number withgetservbyname, map a p原创 2012-08-16 10:01:04 · 4460 阅读 · 2 评论 -
Linux socket-多进程面向连接的服务器客户端程序
总结:1.、TCP的地址复用(address reuse)问题2、HOST_NAME_MAX 的处理方法3、多进程socket编程中 close() 和 shutdown() 的问题4、gethostname() 的问题5、getaddrinfo(hostname, "ruptime", &hint, &ailist) 中 "ruptime" 服务的问题("Servname n原创 2012-09-28 11:25:02 · 3305 阅读 · 0 评论 -
主机名、服务与地址的映射——getaddrinfo(),getnameinfo(),gai_strerror()
/* Structure to contain information about address of a service provider. */struct addrinfo{ int ai_flags; /* Input flags. */ int ai_family; /* Protocol family for socket. */ int ai_sockt原创 2012-08-16 22:27:11 · 17430 阅读 · 1 评论