![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
系统
文章平均质量分 91
深入沟通_it6688668
深入沟通:it6688668
展开
-
[unix]system函数的一个实现
代码来源 unix环境高级编程 第三版 一书 这个system函数实现有缺陷 具体参详10.18节 #include #include #include #include int system(const char *cmdstring) { pid_t pid; int status; struct sigaction ignore,saveintr,savequit; s原创 2017-12-31 11:57:28 · 873 阅读 · 0 评论 -
[unix]线程创建
#include "apue.h" #include pthread_t ntid; void printids(const char *s) { pid_t pid; pthread_t tid; pid = getpid(); /*这里用pthread_self函数获取当前线程id,而不是用pthread_create执行时候保存在全局变量ntid原创 2018-01-11 14:29:39 · 372 阅读 · 0 评论 -
[unix]线程返回值
#include "apue.h" #include struct foo { int a,b,c,d; }; void printfoo(const char *s , const struct foo *fp) { printf("%s",s); printf(" structure at 0x%lx\n",(unsigned long)fp); prin原创 2018-01-11 17:43:48 · 282 阅读 · 1 评论 -
[unix]两个互斥量保护共享变量自增,保证线程执行安全实例
#include "apue.h" #include #define NHASH 29 #define HASH(id) (((unsigned long)id)%NHASH) struct foo *fh[NHASH]; pthread_mutex_t hashlock = PTHREAD_MUTEX_INITIALIZER; struct foo { int原创 2018-01-12 17:58:08 · 302 阅读 · 0 评论 -
[unix]信号处理非局部跳转sigsetjmp函数和siglongjmp实例
#include <apue.h> #include <setjmp.h> #include <time.h> #include <errno.h>static void sig_usr1(int); static void sig_alrm(int); static sigjmp_buf jmpbuf; static volatile sig_atomic_t canjump; void pr_m转载 2017-12-28 17:45:20 · 273 阅读 · 0 评论 -
[unix]sigsuspend函数保护代码临界区 使其不被特定信号中断
#include #include /** * 1 保护代码临界区 使其不被特定信号中断 * 2 当sigsuspend返回时 它将信号屏蔽字设置为调用它之前当值 * SIGINT信号将被阻塞。因此将信号屏蔽恢复为之前保存当值oldmask * 3 在调用sigsuspend时 将SIGUSR1信号加到了进程号屏蔽字中, * 所以当运行该信号处理程序时,得知信号屏蔽字已改变。可见,在转载 2017-12-29 17:32:38 · 218 阅读 · 0 评论