📄 commx.c
字号:
#include <stdio.h> /*stderr*/#include <signal.h> /*SIGCHLD*/#include <unistd.h> /*(fork,execv)*/#include <string.h> /*(strdup)*/#include <sys/wait.h> /*WNOHANG*/#include "commx.h" /*(commxForkExec)*/#include "verbose.h" /*VERB_MISC*/static int commxPid;static voidsigchld(int dummy){ int s; /* wait() for commx exit() only */ /* waitpid(-1,,) messes SOCKS up */ if (waitpid(commxPid, &s, WNOHANG) > 0) { fprintf(stderr, "Comm program exited.\r\n"); verboseOut(VERB_MISC, "Child returns status %d.\r\n", WEXITSTATUS(s)); exit(0); }}static voidforkExec(char *s){ static char *argv[4] = {"sh", "-c", "", NULL}; signal(SIGCHLD, sigchld); commxPid = fork(); switch (commxPid) { case -1: /*error*/ perror("fork()"); exit(1); case 0: /*child*/ signal(SIGCHLD, SIG_DFL); argv[2] = s; execv("/bin/sh", argv); fprintf(stderr, "Could not exec sh.\n"); _exit(127); default: /*parent*/ signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); }}voidcommxForkExec(const char *cmd, char c10, char c01){ char c[3]; char *s; c[0] = c10; c[1] = c01; c[2] = 0; s = strdup(cmd); sprintf(s, cmd, c); /*'%s' -> 'p1' or sth*/ forkExec(s);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -