随笔分类 - UNIX环境高级编程第二版
摘要:#include struct msg { struct msg *m_next; /* ... more stuff here ... */ int m_id;
}; msg* workq;
pthread_cond_t qready = PTHREAD_COND_INITIALIZER;
pthread_mutex_t qlock = PTH...
阅读全文
摘要:// threads/mutex1.c 11-5
#include #include #include struct foo { int f_count; pthread_mutex_t f_lock; int f_id; /* ... more stuff her...
阅读全文
摘要:http://www.apuebook.com/errata2e.html Welcome to the web site dedicated to the support of the second edition of Advanced Programming in the UNIX® Environment. The following errors were fixed in the ...
阅读全文
摘要:// threads/exitstatus.c 11-2
#include "apue.h"
#include void* thr_fn1(void* arg)
{ printf("thread 1 returning\n"); /* return a variable of type void* return a pointer who points ...
阅读全文
摘要:程序清单11-1打印线程ID// threads/threadid.c 11-1
#include "apue.h"
#include pthread_t ntid; void printids(const char* s)
{ printf("%d ", (unsigned int)ntid); printf("%ld ", (uns...
阅读全文
摘要:// signals/sigusr.c 10-1
#include "apue.h" static void sig_usr(int); /* one handler for both signals */ int main(void)
{ if (signal...
阅读全文
摘要:// proc/exec1.c 8-8
#include "apue.h"
#include const char* env_init[] = { "USER=unknown", "PATH=/home/sunyj/apue/proc/", NULL }; int main(void)
{ pid_t pid; if ((pid = ...
阅读全文
摘要:这一节,书中的TELL_WAIT与TELL_PARENT,TELL_CHILD没有弄清楚,到底是如何实现的同步机制。 // proc/tellwait1.c 8-6
#include "apue.h" static void charatatime(const char *); int main(void)
{ pid_t pid; if ((pid = fork()...
阅读全文
摘要:不管进程如何终止,最后都会执行内核中的同一段代码,为相应的进程关闭所有打开描述符,释放它所使用的存储器。无论进程如何终止,我们都希望该进程能够通知其父它是如何终止的,对于exit,_exit,_Exit(一种情况),将其退出状态作为参数传送给函数(exit(3)),对于异常终止(另一种情况),内核产...
阅读全文
摘要:进程ID为0的进程通常是调度进程,常常被称为交换进程swapper,该进程是内核的一部分,这并不执行任何磁盘上的程序,因此也被称为系统进程,进程ID为1是init进程,在自举过程结束时由内核调用,该进程的程序文件为/etc/init或者/sbin/init,此进程负责在自举内核后启动一个UNIX系统...
阅读全文
摘要:// environ/hello1.c#include int main(){ printf("hello, world\n"); return 0;}// g++ hello1.c -o hello1.a// g++ -static hello1.c -o hello1.b , err...
阅读全文
摘要:7.4命令行参数
阅读全文
摘要:可以看出fopen函数是用来打开流(其实应该是说用来打开文件的)的,返回值是一个指向文件对象的指针。通过下面的例子可以知道,fd的使用与对象stdcin,stdcout一样,所以我认为在unix/linux中,对象stdin,stdout的类型应该也是FILE*类型。也就是说stdin,stdout...
阅读全文
摘要:使用标准IO库时,进程(或者是shell)自动打开并关联到程序运行窗口的标准输入输出流对象,为标准输入,标准输出,标准出错,这些流对象引用的文件,与不带缓冲的IO函数使用的文件描述符,它们关联的文件对是相同的,这些文件应该指的就是那些窗口,窗口在显示器上(显示器是文件),如果使用了重定向,那么所谓的...
阅读全文
摘要:UNIX所使用的技术是为每个系统调用在标准C库中设置一个具有同样名字的函数。 从应用角度,可以将系统调用视为C函数
阅读全文
摘要:// program 1-9 proc/shell2.c
#include "apue.h"
#include static void sig_int(int); /* our signal-catching function */ int main(void)
{ char buf[MAXLINE]; /* from apue.h */ pid_t pid;...
阅读全文
摘要:// program 1-7 file/testerror.c#include "apue.h"#include int main(int argc, char *argv[]){ fprintf(stderr, "EACCES: %s\n", strerror(EACCES)); er...
阅读全文
摘要:从标准输入读命令并执行 隐藏行号 复制代码 ? // program 1-5 proc/shell1.c // proc/shell1.c#include "apue.h"#include int main(void){ char buf[MAXLINE]; /* from apue.h */...
阅读全文