随笔分类 - linux
摘要:client.c int get_cmd_type(char *cmd) { //比较输入的指令,找到对应的就返回相对应的指令。 if(!strcmp("ls",cmd)) return LS; if(!strcmp("lls",cmd)) return LLS; if(!strcmp("pwd",
阅读全文
摘要:1. 操作系统概述 2. linux文件io 3. linux文件操作 4. linux进程 进程空间 5. 线程 同步: 条件变量 线程信号量 互斥: 互斥锁 读写锁 线程信号量 6. 进程间通信 管道、信号(unix) 消息队列、共享内存、进程信号量(IPC对象,system V) socket
阅读全文
摘要:目录项的数据结构: struct ext2_dir_entry_2{ __le32 inode; __le16 rec_len; __u8 name_len; __u8 file_type; char name[EXT2_NAME_LEN]; }; 所以在cat userlist这个文件名的时候,会
阅读全文
摘要://reader_writer.c //reader_writer.c #include <sys/ipc.h> #include <sys/shm.h> #include <sys/types.h> #include <unistd.h> #include <error.h> #include <
阅读全文
摘要://account.h #ifndef _ACCOUNT_H #define _ACCOUNT_H typedef struct{ int code; double balance; //定义一把互斥锁,用来对多线程操作的银行账户(共享资源)进行加锁(保护)的 /* 建议一把互斥锁和一个共享资源(银
阅读全文
摘要://write.c #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> struct mymesg{ long mtype;//消息的类型,是一个整数且大于0 char mtex[51
阅读全文
摘要:信号递达:信号的处理动作(绑定的处理函数)。 信号的未决状态:信号从产生到递达之间的状态。 某个信号处于未决状态,一般是因为信号被阻塞(即信号屏蔽字对应的位被置1)了,即当捕获到这个信号时,由于信号处于未决状态,将不会执行信号的处理动作。 int sigemptyset(sigset_t *set)
阅读全文
摘要:同步: //account.h #ifndef _ACCOUNT_H #define _ACCOUNT_H #include <pthread.h> #include <semaphore.h> typedef struct{ int code; double balance; //定义一把互斥锁,
阅读全文
摘要://reader_writer.c #include <pthread.h> #include <stdio.h> #include <unistd.h> /* 写者写完通知读者去读 读者读完通知写者去写 */ typedef struct{ int value; int r_wait; pthre
阅读全文
摘要://account.h #ifndef _ACCOUNT_H #define _ACCOUNT_H #include <pthread.h> typedef struct{ int code; double balance; //定义一把互斥锁,用来对多线程操作的银行账户(共享资源)进行加锁(保护)
阅读全文
摘要://account.h #ifndef _ACCOUNT_H #define _ACCOUNT_H #include <pthread.h> typedef struct{ int code; double balance; //定义一把互斥锁,用来对多线程操作的银行账户(共享资源)进行加锁(保护)
阅读全文
摘要:CPU对变量的计算分为三个步骤: 1. 从内存读取变量到寄存器(如add寄存器) 2. 将读取到的变量进行计算 3. 将寄存器中计算的值写入内存 如有两个线程(线程1和线程2)对共享资源(全局变量)a=0进行自增操作(a++),可能出现如下情况: 线程1进行a++时,会将变量a读取寄存器,在对变量a
阅读全文
摘要:原型: int select(int max fdp1, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) 功能: 委托内核检查描述符集是否准备好(即可以使用,用于双方通信) 参数: fdp1
阅读全文
摘要:fcnt_vector_fd.h #ifndef _FCNTL_VECTOR_FD_H #define _FCNTL_VECTOR_FD_H typedef struct{ int *fd; int conter; int max_conter; }VectorFd; extern VectorFd
阅读全文
摘要://udp_server.c#include <signal.h>#include <stdio.h>#include <errno.h>#include <unistd.h>#include <stdlib.h>#include <time.h>#include <string.h>#includ
阅读全文
摘要:tcp_server_mulpthread.c #include <signal.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include <
阅读全文
摘要:tcp_server_mulprocess.c #include <signal.h> #include <stdio.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include <
阅读全文
摘要:方式: 1. 多进程模型 2. 多线程模型 3. IO多路转换 1. 多进程模型: 父进程循环调用accept来接受客服端的连接,当有客户端连接上来时,就调用fork函数创建子进程来与客户端对接。 如果不创建子进程,那么父进程调用read函数就可能阻塞,就不能实现并发性的处理了。 2. 多线程模型:
阅读全文