
C语言
架起时光机的猪猪侠
噩梦般的修行
展开
-
umask的使用
C Linux umask设置掩码原创 2022-07-10 13:33:56 · 308 阅读 · 1 评论 -
关于fd的close on exec
添加链接描述原创 2021-03-16 16:24:25 · 186 阅读 · 0 评论 -
linux read之后内核做了什么(流程基于linux-kernel-3.12.17)
转载原创 2021-03-16 16:23:19 · 150 阅读 · 0 评论 -
排序去重算法
void runAlgorithn(int arr[], int n_size) { sort(arr); // 先排序 int i = 0, j = 1; for (; j < n_size; j++) { if (arr[i] != arr[j]) { arr[++i] = arr[j]; } } int idx = 0; for (; idx <= i; idx++) { // i+1是不重复数的总数 printf("arr[%d] = %d\n",原创 2021-02-19 23:05:16 · 303 阅读 · 0 评论 -
文件锁的问题
Locks are associated with processes.(文件锁跟进程相关联的.) A process can only have one kind of lock set for each byte of a given file. When any file descriptor for that file(同一进程打开同一份文件多次时,进程会得到不同的fd) is closed by the process, all of the locks that process holds on原创 2021-02-19 09:39:06 · 304 阅读 · 1 评论 -
小端模式 & 大端模式
小端模式, 变量值的低位存于低地址, 变量值高位存于高地址.大端模式, 则与小端模式相反.inline bool IsLittleendian(){ int i = 0x1; return *(char *)&i == 0x1;}int整型在内存中有4Bytes大小int i = 0x1;在内存中, 如果是大端模式,这内存的存储如下|0x00|0x00|0x00|0x01| ^ ^ low-addr high-addr小端模式,在内存的存储如原创 2021-01-17 21:25:55 · 130 阅读 · 0 评论 -
#pragma pack(1) 所起的作用
先给个小例子#include <stdio.h>struct A_st { char c; int i;};#pragma pack(1)struct B_st { char c; int i;};#pragma pack()int main() { printf("sizeof(struct A_st) = %d\n", sizeof(struct A_st)); printf("sizeof(struct B_st) = %d\n", sizeof(s原创 2021-01-17 21:06:29 · 660 阅读 · 0 评论 -
poll函数
select相关 select相关poll其实大体跟select差不多,但是poll没有最大连接数的限制,因为是用链表实现的.poll有给水平触发的特点,如果有读写事件进来了,也给用户返回了,但是用户没有处理该fd,下次轮询,poll还是会继续上报该fd...原创 2021-01-17 09:56:41 · 168 阅读 · 0 评论 -
select函数相关
select调用用户空间的timeout会被拷贝到内核的end_time(设定时间)内核空间会分配6个fdset,分别为in,out,exception(给用户输入用的),还有res_in, res_out, res_exception(3个相应的输出给用户的)用户fd_set会被拷贝到内核in, out, exception遍历所有fd, 调用sock_poll遍历完后, 可能会返回一个mask掩码(如果有读写事件发生的话), 这mask是用来设置fd_set的也有可能没有,要是没有超过ti原创 2021-01-17 09:36:46 · 170 阅读 · 0 评论