摘要:
# 互斥锁 /* #include <pthread.h> int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); 功能:初始化一个互斥变量mutex 参数: 阅读全文
摘要:
# pthread_join /* #include <pthread.h> int pthread_join(pthread_t thread, void **retval); 功能:和一个已经终止的线程进行连接 回收线程的资源 阻塞函数,调用一次只能回收一个线程 任何线程都可以wait其它线程一 阅读全文
摘要:
拥有线程程序的编译需要加 -pthread gcc a.c -o a -pthread /* #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_ro 阅读全文
摘要:
# 终端 # 进程组 # 会话 # 守护进程 // 创建一个会话,每隔2s获取系统时间,并将时间写入到磁盘文件中 #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <s 阅读全文
摘要:
# write.c /* #include <sys/ipc.h> #include <sys/shm.h> int shmget(key_t key, size_t size, int shmflg); 作用:创建一个新的共享内存段,或获取一个既有共享内存段的标识 新创建的段会初始化为0 参数: 阅读全文
摘要:
/* #include <signal.h> int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); 功能:检查或改变信号的处理方式 参数: signum:信号编号 act:处理方式 stru 阅读全文
摘要:
# core文件使用 如果要使用core文件,首先将core设置文件大小 ulimit -a //查看各种文件大小限制 ulimit -c 1024 //将core文件大小设置为1024,c表示core文件,从-a的列表中可以看到 设置大小之后,再进行编译,如果不成功则会生成core文件 使用gdb 阅读全文
摘要:
/* 内存映射: 是将磁盘文件数据映射到内存,用户通过修改内存就能修改磁盘文件 #include <sys/mman.h> void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); 功能:将一个 阅读全文
摘要:
# 父子进程之间示例 /* 有名管道(FIFO) 提供一个路径名与之关联,以FIFO的文件形式存在于文件系统中 读写操作和普通文件一样,常用于不存在关系的进程之间 注意事项: 读写进程只要有一端未打开,另一打开的一端就会阻塞在read或write处 当两端都打开,其中一端关闭时,另一端也停止 通过命 阅读全文
摘要:
匿名管道 /* 匿名管道 用在具有关系的进程间,原因是共享文件描述符 环形队列,双指针-读指针、写指针 管道中没有数据,read将会被堵塞 管道写满时,write将会被堵塞 创建匿名管道 #include <unistd.h> int pipe(int pipefd[2]); 参数: pipefd[ 阅读全文