- 博客(19)
- 资源 (2)
- 收藏
- 关注
原创 多进程并发服务器(笔记)
服务器大致流程图#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <pthread.h>#include <errno.h>#include <signal.h>#include <ctype.h>#include <strings.h>#include &l.
2021-03-14 15:40:42
186
原创 多进程并发服务器(笔记)
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <pthread.h>#include <ctype.h>#include <arpa/inet.h>#include <fcntl.h>#include <errno.h>#define SERV_PORT 800
2021-03-14 15:23:43
230
原创 qt项目-利用MySQL与XML实现车辆管理系统
效果展示数据库数据利用XML文档记录销售记录carmanager.cpp 文件#include "carmanager.h"#include "ui_carmanager.h"#include <QMessageBox>#include <QSqlError>#include <QSqlQuery>#include <QSqlQueryModel>#include <QSqlTableModel>.
2021-03-14 00:06:18
623
原创 利用opendir与readdir函数实现ls功能
函数原型DIR *opendir(char *name);int closedir(DIR *dp);struct dirent *readdir(DIR *dp);struct dirent{inodechar dname[256]}#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <pthread..
2021-03-13 16:52:11
643
原创 web服务器框架
web服务器实现步骤#include <stdio.h>#include <string.h>#include <stdlib.h>#include <netinet/in.h>#include <arpa/inet.h>#include <sys/wait.h>#include <errno.h>#include <sys/types.h>#include <sys/stat.h&.
2021-03-13 16:35:35
331
原创 fcntl()不用重新打开文件就能修改文件属性
普通文件不会阻塞fcntl:int flags = fcntl(fd, F_GETFL);flags |= O_NONBLOCK; 位图–二进制位int ret = fcntl(fd, F_SETFL, flags);获取文件状态: F_GETFL设置文件状态: F_SETFL#icnlude <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#.
2021-03-13 14:45:58
144
原创 利用unlink特性创建temp文件
函数原型int unlink(const char *pathname);执行unlink()函数后删除文件,先检查文件系统中该文件的连接数是否为1,如果不是1说明此文件还有其他链接对象,因此只对此文件的连接数进行减1操作。若连接数为1,并且在此时没有任何进程打开该文件,此内容才会真正地被删除掉。在有进程打开此文件的情况下,则暂时不会删除,直到所有打开该文件的进程都结束时文件就会被删除。#include <stdio.h>#include <stdlib.h>#in.
2021-03-12 23:17:53
139
原创 stat()函数 获取文件类型
1.函数原型int stat(const char *path, struct stat *buf);2.函数结构体struct stat {dev_t st_dev; /* ID of device containing file /ino_t st_ino; / inode number /mode_t st_mode; / protection /nlink_t st_nlink; / number of hard links /.
2021-03-12 23:07:12
886
原创 lseek函数:
/*lseek函数: 文件偏移 linux中可以使用系统函数lseek来修改文件偏移量(读写位置) fseek的作用及参数 SEEK_SEK SEEK_CUR SEEK_END int fseek(FILE *stream, long offset, int whence)成功返回0,失败-1 特别:超出文件末尾位置返回 0;往回超出文件头位置返回-1 off_t lseek(int f
2021-03-12 22:53:23
348
原创 2021-03-12
函数原型int truncate(const char *path,off_t length);#include <stdio.h>#include <srdlib.h>#include <string.h>#include <unistd.h>int main(){ int ret = truncate("filename",250); //文件名 文件大小 return 0;}
2021-03-12 22:45:16
106
原创 利用lseek函数获取文件大小
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <unistd.h>#include <fcntl.h>int main(int argc char *argv[]){ int fd = open(argv[1], O_RDWR); if(fd == -1) { perror("open er
2021-03-12 22:39:04
847
原创 利用read、write函数实现copy功能
ssize_t read(int fd, void *buf, size_t count);参数:fd:文件描述符buf:存数据的缓冲区count:缓冲区的大小返回值:0 读到文件末尾成功; >0 实际从fd读到的数据大小失败:-1,并设置errno将文件设置为非阻塞,当read没有数据时返回-1 且errno设置为EAGAIN or EWOULDBLOCKssize_t write(int fd, const void *buf, size_t count);参数:fd.
2021-03-12 22:32:12
448
原创 文件设置为非阻塞
#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#define MSG_TRY "try again\n"#define MSG_TIMEOUT "time out\n"int main(int argc, char *argv[]){ ch
2021-03-12 22:25:09
255
原创 read()与write()
#####1. 回显STDIN_FILENO事件#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){ int n; char buf[10]; while((n = read(STDIN_FILENO, buf, 10)) != 0) //读取 输入设备的数据 { //将将键盘输入设备获取到的数据打印到屏幕中 write(STDOUT_FILENO, buf, n);
2021-03-12 22:00:42
157
原创 AIO操作代码
#include<stdio.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>#include<assert.h>#include<unistd.h>#include<stdlib.h>#include<
2018-09-27 16:45:42
91
原创 在CentOS中下载并安装python3 笔记
在CentOS中下载并安装python31.安装必要的依赖工具 yum -y install net-tools yum -y install wget //安装下载工具,可以直接在网页中下载资源2.安装相关的依赖包yum install zlib-devel bzip2-devel openssl-devel ncurses-devel ...
2018-09-27 13:17:08
219
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人