Linux-TCP并发模型相关函数接口-014

2024-03-11 21:44

本文主要是介绍Linux-TCP并发模型相关函数接口-014,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1【TCP】多线程模型

相关函数接口已在前面章节介绍,这里不再赘述

源码示例(1):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}void *HandleTcpClient(void *arg)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;int confd = arg;while (1){memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return NULL;}else if (0 == nsize){return NULL;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return NULL;}}return NULL;
}int main(void)
{int sockfd = 0;int confd = 0;pthread_t tid;pthread_attr_t attr;sockfd = CreateListenSocket("192.168.1.183", 50000);pthread_attr_init(&attr);pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);while (1){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");return -1;}pthread_create(&tid, &attr, HandleTcpClient, confd);}close(sockfd);return 0;
}

2【IO】模型

2.1阻塞IO

相关函数接口已在前面章节介绍,这里不再赘述

2.2非阻塞IO

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}flags = fcntl(fd, F_GETFL);flags |= O_NONBLOCK;fcntl(fd, F_SETFL, flags);flags = fcntl(0, F_GETFL);flags |= O_NONBLOCK;fcntl(0, F_SETFL, flags);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));pret = gets(tmpbuff);if (pret != NULL){printf("STDIN:%s\n", tmpbuff);}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = read(fd, tmpbuff, sizeof(tmpbuff));if (nsize > 0){printf("FIFO:%s\n", tmpbuff);}}close(fd);return 0;
}

2.3异步IO

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int fd = 0;void handler(int signo)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = read(fd, tmpbuff, sizeof(tmpbuff));if (nsize > 0){printf("FIFO:%s\n", tmpbuff);}return;
}int main(void)
{int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};signal(SIGIO, handler);mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}flags = fcntl(fd, F_GETFL);flags |= O_ASYNC;fcntl(fd, F_SETFL, flags);fcntl(fd, F_SETOWN, getpid());while (1){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}close(fd);
}

2.4多路复用IO

2.4.1【select】

2.4.1.1函数原型
【int select(int nfds, fd_set *readfds, fd_set *writefds,fd_set *exceptfds, struct timeval *timeout);】
2.4.1.2函数功能
监听文件描述符集合中是否有文件描述编程ready状态
2.4.1.3函数参数
1.【nfds】:最大文件描述符的值+1 
2.【readfds】:读文件描述符集合
3.【writefds】:写文件描述符集合
4.【exceptfds】:其余文件描述符集合
5.【timeout】:等待的时长【NULL】:表示一直等待
2.4.1.4返回值
【成功】:返回文件描述符集合中的文件描述符个数
【失败】:返回【-1】
2.4.1.5常用的几个函数

1.【FD_CLR】

(1)函数原型:【void FD_CLR(int fd, fd_set *set);】
(2)函数功能: 将文件描述符fd从集合中清除 
(3)函数参数:【fd】:【set】:

(4)返回值:

2.【FD_ISSET】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 判断文件描述符fd是否仍在集合中
(3)函数参数:【fd】:【set】:
(4)返回值:

3.【FD_SET】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 将文件描述符fd加入到集合中
(3)函数参数:【fd】:【set】:
(4)返回值:

4.【FD_ZERO】

(1)函数原型:【int  FD_ISSET(int fd, fd_set *set);】
(2)函数功能: 将文件描述符集合清0
(3)函数参数:
【set】:
(4)返回值:

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};fd_set rdfds;fd_set tmpfds;int ret = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}FD_ZERO(&rdfds);FD_SET(fd, &rdfds);FD_SET(0, &rdfds);while (1){tmpfds = rdfds;ret = select(fd+1, &tmpfds, NULL, NULL, NULL);if (-1 == ret){perror("fail to select");return -1;}if (FD_ISSET(fd, &tmpfds)){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}if (FD_ISSET(0, &tmpfds)){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}}close(fd);return 0;
}

源码示例(2):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}int HandleTcpClient(int confd)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}else if (0 == nsize){return 0;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}return nsize;
}int main(void)
{int sockfd = 0;int confd = 0;fd_set rdfds;fd_set tmpfds;int maxfd = 0;int ret = 0;int i = 0;sockfd = CreateListenSocket("192.168.1.183", 50000);FD_ZERO(&rdfds);FD_SET(sockfd, &rdfds);maxfd = sockfd;while (1){tmpfds = rdfds;ret = select(maxfd+1, &tmpfds, NULL, NULL, NULL);if (-1 == ret){perror("fail to select");return -1;}if (FD_ISSET(sockfd, &tmpfds)){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");FD_CLR(sockfd, &rdfds);close(sockfd);continue;}FD_SET(confd, &rdfds);maxfd = maxfd > confd ? maxfd : confd;}for (i = sockfd+1; i <= maxfd; i++){if (FD_ISSET(i, &tmpfds)){ret = HandleTcpClient(i);if (-1 == ret){fprintf(stderr, "handle client failed!\n");FD_CLR(i, &rdfds);close(i);continue;}else if (0 == ret){fprintf(stderr, "client disconnected!\n");FD_CLR(i, &rdfds);close(i);continue;}}}}close(confd);close(sockfd);return 0;
}

2.4.2【poll】

2.4.2.1函数原型
【int poll(struct pollfd *fds, nfds_t nfds, int timeout);】
2.4.2.2函数功能
监听文件描述符集合是否有事件发生
2.4.2.3函数参数
1.【fds】:监听文件描述符集合数组空间首地址
2.【nfds】:监听文件描述符集合元素个数
3.【timeout】:等待的时间【-1】: 一直等待

结构体说明:

struct pollfd {int   fd;/* file descriptor 监听的文件描述符*/short events;/* requested events 要监听的事件*/short revents;/* returned events 实际产生的事件*/
};
//结构体成员介绍
fd:监听的文件描述符
events:要监听的事件  POLLIN:是否可读  POLLOUT:是否可写
revents:实际产生的事件 
2.4.2.4返回值
【成功】:返回产生事件的文件描述符个数
【失败】:返回【-1】

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};struct pollfd fds[2];int nready = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}fds[0].fd = fd;fds[0].events = POLLIN;fds[1].fd = 0;fds[1].events = POLLIN;while (1){nready = poll(fds, 2, -1);if (-1 == nready){perror("fail to poll");return -1;}if (fds[0].revents & POLLIN){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}if (fds[1].revents & POLLIN){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}}close(fd);
}

源码示例(2):

//【client.c】
int CreateTcpClient(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = connect(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to connect");return -1;}return sockfd;
}int main(void)
{int sockfd = 0;char tmpbuff[4096] = {"hello world"};int cnt = 0;ssize_t nsize = 0;sockfd = CreateTcpClient("192.168.1.183", 50000);while (1){memset(tmpbuff, 0, sizeof(tmpbuff));sprintf(tmpbuff, "hello world --- %d", cnt);cnt++;nsize = send(sockfd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(sockfd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}printf("RECV:%s\n", tmpbuff);}close(sockfd);return 0;
}//【server.c】
int CreateListenSocket(char *pip, int port)
{int ret = 0;int sockfd = 0;struct sockaddr_in seraddr;sockfd = socket(AF_INET, SOCK_STREAM, 0);if (-1 == sockfd){perror("fail to socket");return -1;}seraddr.sin_family = AF_INET;seraddr.sin_port = htons(port);seraddr.sin_addr.s_addr = inet_addr(pip);ret = bind(sockfd, (struct sockaddr *)&seraddr, sizeof(seraddr));if (-1 == ret){perror("fail to bind");return -1;}ret = listen(sockfd, 10);if (-1 == ret){perror("fail to listen");return -1;}return sockfd;
}int HandleTcpClient(int confd)
{char tmpbuff[4096] = {0};ssize_t nsize = 0;memset(tmpbuff, 0, sizeof(tmpbuff));nsize = recv(confd, tmpbuff, sizeof(tmpbuff), 0);if (-1 == nsize){perror("fail to recv");return -1;}else if (0 == nsize){return 0;}sprintf(tmpbuff, "%s ----echo", tmpbuff);nsize = send(confd, tmpbuff, strlen(tmpbuff), 0);if (-1 == nsize){perror("fail to send");return -1;}return nsize;
}int InitFds(struct pollfd *fds, int maxlen)
{int i = 0;for (i = 0; i < maxlen; i++){fds[i].fd = -1;}return 0;
}int AddFd(struct pollfd *fds, int maxlen, int fd, short env)
{int i = 0;for (i = 0; i < maxlen; i++){if (fds[i].fd == -1){fds[i].fd = fd;fds[i].events = env;break;}}if (i == maxlen){return -1;}return 0;
}int DeleteFd(struct pollfd *fds, int maxlen, int fd)
{int i = 0;for (i = 0; i < maxlen; i++){if (fds[i].fd == fd){fds[i].fd = -1;break;}}return 0;
}int main(void)
{int sockfd = 0;int confd = 0;struct pollfd fds[1024];int nready = 0;int i = 0;int ret = 0;sockfd = CreateListenSocket("192.168.1.183", 50000);InitFds(fds, 1024);AddFd(fds, 1024, sockfd, POLLIN);while (1){nready = poll(fds, 1024, -1);if (-1 == nready){perror("fail to poll");return -1;}for (i = 0; i < 1024; i++){if (fds[i].fd == -1){continue;}if (fds[i].revents & POLLIN && fds[i].fd == sockfd){confd = accept(sockfd, NULL, NULL);if (-1 == confd){perror("fail to accept");DeleteFd(fds, 1024, sockfd);close(sockfd);continue;}AddFd(fds, 1024, confd, POLLIN);}else if (fds[i].revents & POLLIN && fds[i].fd != sockfd){ret = HandleTcpClient(fds[i].fd);if (-1 == ret){fprintf(stderr, "handle tcp client failed!\n");close(fds[i].fd);DeleteFd(fds, 1024, fds[i].fd);continue;}else if (0 == ret){fprintf(stderr, "client disconnected!\n");close(fds[i].fd);DeleteFd(fds, 1024, fds[i].fd);continue;}}}}close(sockfd);return 0;
}

2.4.3【epoll】

2.4.3.1函数原型

【int epoll_create(int size);】

2.4.3.2函数功能
创建一张内核事件表
2.4.3.3函数参数
【size】:事件的个数
2.4.3.4返回值
【成功】:返回文件描述符
【失败】:返回【-1】

2.4.4【epoll_ctl】

2.4.4.1函数原型

【int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);】

2.4.4.2函数功能

维护epoll时间表

2.4.4.3函数参数
1.【epfd】:事件表的文件描述符
2.【op】:【EPOLL_CTL_ADD】:添加事件【EPOLL_CTL_MOD】:修改事件【EPOLL_CTL_DEL】:删除事件
3.【fd】:操作的文件描述符
4.【event】:事件对应的事件

结构体说明:

typedef union epoll_data {void        *ptr;int          fd;uint32_t     u32;uint64_t     u64;
} epoll_data_t;struct epoll_event {uint32_t     events;      /* Epoll events */epoll_data_t data;        /* User data variable */
};
2.4.4.4返回值
【成功】:返回【0】 
【失败】:返回【-1】

2.4.5【epoll_wait】

2.4.5.1函数原型
【int epoll_wait(int epfd, struct epoll_event *events,int maxevents, int timeout);】
2.4.5.2函数功能
监听事件表中的事件
2.4.5.3函数参数
1.【epfd】:文件描述符
2.【events】:存放实际产生事件的数组空间首地址
3.【maxevents】:最多存放事件的个数
4.【timeout】:设定监听的时间(超过该时间则不再监听)【-1】:一直监听直到有事件发生
2.4.5.4返回值
【成功】:返回产生事件的文件描述符个数
【失败】:返回【-1】
【超时】:如果时间达到仍没有事件发生返回【0】

源码示例(1):

//【write.c】
int main(void)
{int fd = 0;char tmpbuff[4096] = {0};mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_WRONLY);if (-1 == fd){perror("fail to open");return -1;}while (1){gets(tmpbuff);write(fd, tmpbuff, strlen(tmpbuff));}close(fd);return 0;
}//【read.c】
int main(void)
{int fd = 0;int flags = 0;char *pret = NULL;ssize_t nsize = 0;char tmpbuff[4096] = {0};int epfd = 0;struct epoll_event env;struct epoll_event retenv[2];int nready = 0;int i = 0;mkfifo("/tmp/myfifo", 0664);fd = open("/tmp/myfifo", O_RDONLY);if (-1 == fd){perror("fail to open");return -1;}epfd = epoll_create(2);if (-1 == epfd){perror("fail to epoll_create");return -1;}env.events = EPOLLIN;env.data.fd = fd;epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &env);env.events = EPOLLIN;env.data.fd = 0;epoll_ctl(epfd, EPOLL_CTL_ADD, 0, &env);while (1){nready = epoll_wait(epfd, retenv, 2, -1);if (-1 == nready){perror("fail to epoll_wait");return -1;}for (i = 0; i < nready; i++){if (retenv[i].data.fd == 0){memset(tmpbuff, 0, sizeof(tmpbuff));gets(tmpbuff);printf("STDIN:%s\n", tmpbuff);}else if (retenv[i].data.fd == fd){memset(tmpbuff, 0, sizeof(tmpbuff));read(fd, tmpbuff, sizeof(tmpbuff));printf("FIFO:%s\n", tmpbuff);}}}close(fd);
}

源码示例(2):

这篇关于Linux-TCP并发模型相关函数接口-014的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/799174

相关文章

Linux磁盘分区、格式化和挂载方式

《Linux磁盘分区、格式化和挂载方式》本文详细介绍了Linux系统中磁盘分区、格式化和挂载的基本操作步骤和命令,包括MBR和GPT分区表的区别、fdisk和gdisk命令的使用、常见的文件系统格式以... 目录一、磁盘分区表分类二、fdisk命令创建分区1、交互式的命令2、分区主分区3、创建扩展分区,然后

Linux中chmod权限设置方式

《Linux中chmod权限设置方式》本文介绍了Linux系统中文件和目录权限的设置方法,包括chmod、chown和chgrp命令的使用,以及权限模式和符号模式的详细说明,通过这些命令,用户可以灵活... 目录设置基本权限命令:chmod1、权限介绍2、chmod命令常见用法和示例3、文件权限详解4、ch

Linux内核之内核裁剪详解

《Linux内核之内核裁剪详解》Linux内核裁剪是通过移除不必要的功能和模块,调整配置参数来优化内核,以满足特定需求,裁剪的方法包括使用配置选项、模块化设计和优化配置参数,图形裁剪工具如makeme... 目录简介一、 裁剪的原因二、裁剪的方法三、图形裁剪工具四、操作说明五、make menuconfig

Linux使用nohup命令在后台运行脚本

《Linux使用nohup命令在后台运行脚本》在Linux或类Unix系统中,后台运行脚本是一项非常实用的技能,尤其适用于需要长时间运行的任务或服务,本文我们来看看如何使用nohup命令在后台... 目录nohup 命令简介基本用法输出重定向& 符号的作用后台进程的特点注意事项实际应用场景长时间运行的任务服

什么是cron? Linux系统下Cron定时任务使用指南

《什么是cron?Linux系统下Cron定时任务使用指南》在日常的Linux系统管理和维护中,定时执行任务是非常常见的需求,你可能需要每天执行备份任务、清理系统日志或运行特定的脚本,而不想每天... 在管理 linux 服务器的过程中,总有一些任务需要我们定期或重复执行。就比如备份任务,通常会选在服务器资

Redis的Hash类型及相关命令小结

《Redis的Hash类型及相关命令小结》edisHash是一种数据结构,用于存储字段和值的映射关系,本文就来介绍一下Redis的Hash类型及相关命令小结,具有一定的参考价值,感兴趣的可以了解一下... 目录HSETHGETHEXISTSHDELHKEYSHVALSHGETALLHMGETHLENHSET

Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)

《Python基于火山引擎豆包大模型搭建QQ机器人详细教程(2024年最新)》:本文主要介绍Python基于火山引擎豆包大模型搭建QQ机器人详细的相关资料,包括开通模型、配置APIKEY鉴权和SD... 目录豆包大模型概述开通模型付费安装 SDK 环境配置 API KEY 鉴权Ark 模型接口Prompt

Linux限制ip访问的解决方案

《Linux限制ip访问的解决方案》为了修复安全扫描中发现的漏洞,我们需要对某些服务设置访问限制,具体来说,就是要确保只有指定的内部IP地址能够访问这些服务,所以本文给大家介绍了Linux限制ip访问... 目录背景:解决方案:使用Firewalld防火墙规则验证方法深度了解防火墙逻辑应用场景与扩展背景:

python中的与时间相关的模块应用场景分析

《python中的与时间相关的模块应用场景分析》本文介绍了Python中与时间相关的几个重要模块:`time`、`datetime`、`calendar`、`timeit`、`pytz`和`dateu... 目录1. time 模块2. datetime 模块3. calendar 模块4. timeit

Linux下MySQL8.0.26安装教程

《Linux下MySQL8.0.26安装教程》文章详细介绍了如何在Linux系统上安装和配置MySQL,包括下载、解压、安装依赖、启动服务、获取默认密码、设置密码、支持远程登录以及创建表,感兴趣的朋友... 目录1.找到官网下载位置1.访问mysql存档2.下载社区版3.百度网盘中2.linux安装配置1.