上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 86 下一页
摘要: # 字节序转换函数、IP地址转换函数 /* 网络字节序采用大端 网络通信时,需要将主机字节序转换成网络字节序(大端), 另外一个主机获取到数据后根据情况将网络字节序转换成主机字节序 #include <arpa/inet.h> // 转换32位数据,一般用于转换ip uint32_t htonl(u 阅读全文
posted @ 2023-05-09 11:01 WTSRUVF 阅读(28) 评论(0) 推荐(0)
摘要: 有几个线程就有几个除互斥信号之外的信号量,每个线程等待自己的信号量有位置, 并最后给其他信号量位置。初始时,生产者的值非0,消费者的值为0。 /* #include <semaphore.h> int sem_init(sem_t *sem, int pshared, unsigned int va 阅读全文
posted @ 2023-05-07 09:29 WTSRUVF 阅读(21) 评论(0) 推荐(0)
摘要: # 互斥锁 /* #include <pthread.h> int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); 功能:初始化一个互斥变量mutex 参数: 阅读全文
posted @ 2023-05-06 11:54 WTSRUVF 阅读(38) 评论(0) 推荐(0)
摘要: # pthread_join /* #include <pthread.h> int pthread_join(pthread_t thread, void **retval); 功能:和一个已经终止的线程进行连接 回收线程的资源 阻塞函数,调用一次只能回收一个线程 任何线程都可以wait其它线程一 阅读全文
posted @ 2023-05-04 10:58 WTSRUVF 阅读(190) 评论(0) 推荐(0)
摘要: 拥有线程程序的编译需要加 -pthread gcc a.c -o a -pthread /* #include <pthread.h> int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_ro 阅读全文
posted @ 2023-05-02 11:24 WTSRUVF 阅读(29) 评论(0) 推荐(0)
摘要: # 终端 # 进程组 # 会话 # 守护进程 // 创建一个会话,每隔2s获取系统时间,并将时间写入到磁盘文件中 #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <s 阅读全文
posted @ 2023-05-02 10:10 WTSRUVF 阅读(22) 评论(0) 推荐(0)
摘要: # write.c /* #include <sys/ipc.h> #include <sys/shm.h> int shmget(key_t key, size_t size, int shmflg); 作用:创建一个新的共享内存段,或获取一个既有共享内存段的标识 新创建的段会初始化为0 参数: 阅读全文
posted @ 2023-05-01 16:19 WTSRUVF 阅读(54) 评论(0) 推荐(0)
摘要: /* #include <signal.h> int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); 功能:检查或改变信号的处理方式 参数: signum:信号编号 act:处理方式 stru 阅读全文
posted @ 2023-05-01 10:36 WTSRUVF 阅读(34) 评论(0) 推荐(0)
摘要: # core文件使用 如果要使用core文件,首先将core设置文件大小 ulimit -a //查看各种文件大小限制 ulimit -c 1024 //将core文件大小设置为1024,c表示core文件,从-a的列表中可以看到 设置大小之后,再进行编译,如果不成功则会生成core文件 使用gdb 阅读全文
posted @ 2023-04-30 22:09 WTSRUVF 阅读(26) 评论(0) 推荐(0)
摘要: /* 内存映射: 是将磁盘文件数据映射到内存,用户通过修改内存就能修改磁盘文件 #include <sys/mman.h> void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); 功能:将一个 阅读全文
posted @ 2023-04-29 15:15 WTSRUVF 阅读(75) 评论(0) 推荐(0)
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 86 下一页