当前位置:网站首页 > 技术博客 > 正文

给进程发sigkill信号



#include <stdio.h> #include <string.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h> #include <signal.h> #define SERV_PORT 8000 int main(int argc, const char * argv[]) { struct sockaddr_in serverAdd; struct sockaddr_in clientAdd; bzero(&serverAdd, sizeof(serverAdd)); serverAdd.sin_family = AF_INET; serverAdd.sin_addr.s_addr = htonl(INADDR_ANY); serverAdd.sin_port = htons(SERV_PORT); socklen_t clientAddrLen; int listenfd = socket(AF_INET, SOCK_STREAM, 0); int yes = 1; setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes)); if (listenfd < 0) { printf("创建socket失败 "); return -1; } int bindResult = bind(listenfd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)); if (bindResult < 0) { printf("绑定端口失败 "); close(listenfd); return -1; } listen(listenfd, 20); int connfd; unsigned char recvMsg[]; unsigned long long totalSize = 0; clientAddrLen = sizeof(clientAdd); connfd = accept(listenfd,(struct sockaddr *)&clientAdd,&clientAddrLen); if (connfd < 0) { print#include <stdio.h> #include <string.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #include <errno.h> #include <signal.h> #define SERV_PORT 8000 int main(int argc, const char * argv[]) { struct sockaddr_in serverAdd; struct sockaddr_in clientAdd; bzero(&serverAdd, sizeof(serverAdd)); serverAdd.sin_family = AF_INET; serverAdd.sin_addr.s_addr = htonl(INADDR_ANY); serverAdd.sin_port = htons(SERV_PORT); socklen_t clientAddrLen; int listenfd = socket(AF_INET, SOCK_STREAM, 0); int yes = 1; setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(yes)); if (listenfd < 0) { printf("创建socket失败 "); return -1; } int bindResult = bind(listenfd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)); if (bindResult < 0) { printf("绑定端口失败 "); close(listenfd); return -1; } listen(listenfd, 20); int connfd; unsigned char recvMsg[]; unsigned long long totalSize = 0; clientAddrLen = sizeof(clientAdd); connfd = accept(listenfd,(struct sockaddr *)&clientAdd,&clientAddrLen); if (connfd < 0) { printf("连接失败 "); return -1; } else{ // 这里我们用于测试,只接收一个连接  close(listenfd); } close(connfd); return 0; }f("连接失败 "); return -1; } else{ // 这里我们用于测试,只接收一个连接  close(listenfd); } close(connfd); return 0; }

版权声明


相关文章:

  • lspci | grep -i net2024-12-07 20:30:04
  • emwin appwizard使用教程2024-12-07 20:30:04
  • ubuntu ibus输入不了中文2024-12-07 20:30:04
  • “免费的编程自学网站”2024-12-07 20:30:04
  • python threadpool2024-12-07 20:30:04
  • 红黑树的实现原理和应用场景2024-12-07 20:30:04
  • 五笔输入法86版官方下载2024-12-07 20:30:04
  • windows录制gif2024-12-07 20:30:04
  • eventloop阮一峰2024-12-07 20:30:04
  • mysql版本怎么看2024-12-07 20:30:04