From 05046725b7eb821010414fab304e77a344ad5256 Mon Sep 17 00:00:00 2001 From: chenyf <1343619937@qq.com> Date: Tue, 27 Feb 2024 20:28:51 +0800 Subject: [PATCH] 1 --- .vscode/settings.json | 6 ++ child_porcess_clean/clear.c | 50 +++++++++++ child_porcess_clean/run.sh | 3 + child_porcess_clean/test.bin | Bin 0 -> 16248 bytes deamon/daemon.c | 158 +++++++++++++++++++++++++++++++++++ deamon/log.txt | 0 deamon/run.sh | 7 ++ deamon/test.bin | Bin 0 -> 16888 bytes exec/app.bin | Bin 0 -> 15960 bytes exec/app.c | 6 ++ exec/exec.c | 39 +++++++++ exec/run.sh | 4 + exec/test.bin | Bin 0 -> 16168 bytes 13 files changed, 273 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 child_porcess_clean/clear.c create mode 100755 child_porcess_clean/run.sh create mode 100755 child_porcess_clean/test.bin create mode 100644 deamon/daemon.c create mode 100644 deamon/log.txt create mode 100755 deamon/run.sh create mode 100755 deamon/test.bin create mode 100755 exec/app.bin create mode 100644 exec/app.c create mode 100644 exec/exec.c create mode 100755 exec/run.sh create mode 100755 exec/test.bin diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..226bb33 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "wait.h": "c", + "stat.h": "c" + } +} \ No newline at end of file diff --git a/child_porcess_clean/clear.c b/child_porcess_clean/clear.c new file mode 100644 index 0000000..95e9324 --- /dev/null +++ b/child_porcess_clean/clear.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void process_clean() +{ + while (wait(NULL) != -1) + { + printf("child clean\n"); + } + + return 0; +} +int main(int argc, char *argv[]) +{ + signal(SIGCHLD, process_clean); + for (int i = 0; i < 10; i++) + { + pid_t pid = fork(); + if (pid == 0) + { + sleep(1); + exit(0); + } + else if (pid > 0) + { + int status; + // wait(&status); + // printf("Child %d exited with status %d\n", pid, status); + } + else + { + perror("fork"); + } + } + int k = 5; + while (k--) + { + sleep(1); + } + + return 0; +} \ No newline at end of file diff --git a/child_porcess_clean/run.sh b/child_porcess_clean/run.sh new file mode 100755 index 0000000..3160891 --- /dev/null +++ b/child_porcess_clean/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +gcc -o test.bin clear.c +./test.bin \ No newline at end of file diff --git a/child_porcess_clean/test.bin b/child_porcess_clean/test.bin new file mode 100755 index 0000000000000000000000000000000000000000..c22791a6976d3538742efe2bdaf1e53b591e5926 GIT binary patch literal 16248 zcmeHOe{2-T6`nH?Oak_iKw}_*gAx>)_^`oHNaAo{pE*b7N5QD+k92ePt?eu4JNIrc z*ij))+_bg`tx=_vKO!}eDuGm_x<68ZDufXY5Q$VEwGybUp)dEdNmX7=su-mG`#xoAsMSsSlvPPbc?ggBQ{W}oi3LZV!80s2w7LfnId?fO)DUJ$jG`x>kfQpkF@2&1#zpi>+T{xEsueQ3t{R+{+V`|H` z-HNIiWlqAV%KB{^^>NueDQEv<5B&1s3q6%@f8`H9Uz$1jQN{Ze={fAf{bmjOaN_zf zMA+v1Y&zJ-j>q$qvpL2~`fs`!OC_%V?jnVIhzk|rR}xpue_09sJH&_R@TSL!C{|Cj z1phMeAv(M%OhmDIHk9D&O7H>V`5Zo$G_Aciu5~2S@l^6zU1=H(gmx`w#IuIh9Z#lJ zF4;+CswZ#cR4%3KJ*p#<-J|x#lZNWiv)N2m>AjR^9gmlFYD-J=<_2wbcy)NKlV4M( zwC2{WT0+n2oynY`XIr;6q%vu}HQtuuW;?qxX=zroU5h&MhzQUqnO5+ZZ94_1{0Yk9 ze#kFO&f-zkD%>v)y-dTXOg(M8JI^UR9}w(ec@BXemEVW*h%E#U`|?Jc=P}B$MjCVR z?r}Zt;;rYj2(G($w82GFE}riPq*sOKp8>>x%Z|EuzR!?GT)cfh*(Jway!@nC1*0yW z0_mjlF8)r3RqCRPzstq@Sw8}P1pEm25%446N5GH3|0@FTS1$fXY~bDU*nt^WRw)&G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include +#include +#include +#include +#include + +#define CREAT_PID_FILE_PATH "/tmp/mydaemon.pid" +#define LOG_FILE_NAME "log.txt" +#define SUCCESS() fprintf(stdout, "success\n") +void daemonize(const char *cmd) +{ + pid_t pid, sid; + + // Fork off the parent process + pid = fork(); + // An error occurred + if (pid < 0) + { + + fprintf(stderr, "can not creat process\n"); + exit(EXIT_FAILURE); + } + // Success: Let the parent terminate + if (pid > 0) + { + exit(EXIT_SUCCESS); + } + + // On success: The child process becomes session leader + if ((sid = setsid()) < 0) + { + fprintf(stderr, "can not new secion\n"); + exit(EXIT_FAILURE); + } + + // Catch, ignore and handle signals + signal(SIGCHLD, SIG_IGN); + signal(SIGHUP, SIG_IGN); + // Fork off for the second time + pid = fork(); + + // An error occurred + if (pid < 0) + { + fprintf(stderr, "can not creat process\n"); + exit(EXIT_FAILURE); + } + + // Success: Let the parent terminate + if (pid > 0) + { + exit(EXIT_SUCCESS); + } + + // Set new file permissions + umask(0); + + // Change the working directory to the root directory + // or another appropriated directory + if ((chdir("/")) < 0) + { + exit(EXIT_FAILURE); + } + + // Open the /dev/null file + // open("/dev/null", O_RDWR); + // open("/dev/null", O_RDWR); + + // Write the PID to the pidfile + FILE *fp; + fp = fopen(CREAT_PID_FILE_PATH, "w"); + if (fp != NULL) + { + fprintf(fp, "%d\n", getpid()); + fclose(fp); + } + else + { + fprintf(stdout, "create file error\n"); + exit(EXIT_FAILURE); + } + fprintf(stdout,"server start...\n"); + // Close all open file descriptors + int x; + for (x = sysconf(_SC_OPEN_MAX); x >= 0; x--) + { + close(x); + } + // Open the /dev/null file + open("/dev/null", O_RDWR); + open("/dev/null", O_RDWR); + // Now we can do the tasks of the daemon + while (1) + { + // Your daemon code here + sleep(1); + fprintf(stdout, "Daemon is running...\n"); + } +} + +int main(int argc, char *argv[]) +{ + const char *cmd = "mydaemon"; + // Check for a valid command line argument + if (argc < 2) + { + fprintf(stderr, "Usage: %s start|stop\n", cmd); + exit(EXIT_FAILURE); + } + + // Check the command line argument + if (strcmp(argv[1], "start") == 0) + { + // 测试下是否已经有个进程了 + int exit = access(CREAT_PID_FILE_PATH, F_OK); + if (exit == 0) + { + fprintf(stderr, "the server is exited, so safe exit\n"); + return 0; + } + else + { + fprintf(stdout, " try to start server\n"); + } + daemonize(cmd); + } + else if (strcmp(argv[1], "stop") == 0) + { + // Code to stop the daemon + FILE *fp; + pid_t pid; + + fp = fopen(CREAT_PID_FILE_PATH, "r"); + if (fp != NULL) + { + + fscanf(fp, "%d", &pid); + fclose(fp); + kill(pid, SIGTERM); + remove(CREAT_PID_FILE_PATH); + fprintf(stdout, "server stop...\n"); + } + else + { + printf(" no find the process\n"); + } + } + else + { + fprintf(stderr, "Usage: %s start|stop\n", cmd); + exit(EXIT_FAILURE); + } + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/deamon/log.txt b/deamon/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/deamon/run.sh b/deamon/run.sh new file mode 100755 index 0000000..c9f563d --- /dev/null +++ b/deamon/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if [ "$1" = "ps" ];then + ps -aux | grep test +else + gcc -o test.bin daemon.c + ./test.bin $1 +fi \ No newline at end of file diff --git a/deamon/test.bin b/deamon/test.bin new file mode 100755 index 0000000000000000000000000000000000000000..fbceec6b03084a432d1a7a924be08e6d41a38e73 GIT binary patch literal 16888 zcmeHOeQX@ZbstisttgU6B~q-&k+uF%B3tH>lqFemEc^6v@~MzyMHZ2?wYxg<_Q-?p zD|dSm>6nUaMuAv~fDEMhK;pt_;o3zKKyDq^F@Z1}Ej66!2B zavJ;kdo%AX_qMlb5%fRb5XU#~_daIk?d;6X?#$<7yLYy?wJAyS)E$br=?@ts%7RU| zaRwx+HmODUze-)Bt^nVmF(Z!}0;x$C+8gP7#^-^O-Ezt_p&v7_5-K$$N_JtX`-4Uz zRCODk>^dpSe2~6mZcFt9mo(!Hw&CGs&JzI#(X;8Qrw8XXE-vDIZy< zt3dU#@S{F;*WLjIH`9d4F9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ndu9YZQh4Fkl}n|8>Y|n>pQsl;r)8 zoKp_!3orB{Y`X9hds)A(=^<}({nc=Dyx6}B0rg$6mvyC_JD2n2bpKHjJGqYE0!Hx@ zdwG9k^^&$yGy4DBKd~2j1&sanD$2TjhDtf&LF|NI2xG#$@}ox5&Gt-0U0GhvWR`IG zK|Qfw8_=h^Qu0&jJ4RyuN7-S4`~OP7bZbccW&EZ0AX0Z@Y5t$yV5rPTB9n53r`xre P{qoI5V@1Fqz^eZSnQ!Ru literal 0 HcmV?d00001 diff --git a/exec/app.bin b/exec/app.bin new file mode 100755 index 0000000000000000000000000000000000000000..2430bdec63dc260fd7bb6530ba8f53bc8d45860d GIT binary patch literal 15960 zcmeHOYit}>6~4QU6Q_0TO_~tLfp`U_G*q70j%`AboAoo}%6Zgr1W3Sm>|NU{?ZfQO zQg2mSR{@08Mhg6Z3aZjdNUa2w`hy=vAk|eLv`AEq_(3X!6e^5dsSl@66kZw5xpThB zcvz=W1wSgym3F^-9^bil&fJ;3vvcqL!($`ySWKbRsXG))lL=3g62rs2QXxpGBWeeI zx2XeaE6H25&ae(Q2 z7$1-ZfUx`RC7DbmslR=EQ$%2p$6Z-&_Z*h{HsTi~FO!1cvB#a7mY66F!w7-A0AW3PMlE` zW`%WpSeex5_@;Z|1NM7mkM^!ZOAO z`*`_yfYnl0>O$s~yjE=T#qoF5u$iPw*3f^PbhZ4`oA{SE(Q|(})_)btnqIK2nQXz% zW$(!-%c8_jTV=;CIac1z7Sw#jDJxcT@_W^>vC)A+tIOyzdi?s~Ze@*59JkV$Qf4+= zb~2@j7-b;JK$L+f15pN|3`7}-GVtNgz+ajV{KGu^W`p@) z{cDGmGQYXv#NAiTv(Gm?rw`8U`2nflbwBw-g61~G{&Q@3_l-Zgu6v$kvOcA)LrU98 zt_0=Iw?>yPe8pUP-8}oJ^-~kWohzL$o9Fs|O;OxEr^)lLGe&dUH*|ZXuad?*S6^cI z>=kDZb*-1{)V1yIrRKIpc6?5d{71Ea&j7>0t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Dn7sDGU9s_l1 z%Fbsgm`A4+D}zR8o(5j%!uWt9&u8e8qI!hH?~|SR1LB8yDG+&LKG(zi$4SRIL45yr zL4F@FUndt`B)t&TBUB6Wlfv`S_w*|G*#SNg;-|y_gdf5{20k6)pArKQew*=s9^y|5 z0k|tPV8Zd93Gp%S0PaA;g5mtVAbgyEl@v!o|M^PPVg7GO&s_w+5j??evIR?+|9dh9 z`KhGm4g6`4Om&POs8^{%Yft?>TzJmIKFF{?WZ-4uHV6244qRy`B^CI2(lr_Sf0Kd7 zE}nldZ^gb=>|f>Uj|+G>k3S(DA3ykb4qQIO-n6LJ1OFR*;8r3B`6?x@9Uh_`1ON|m zBavB$_A$Rp2tVx4Z3W9tX + +int main(int argc ,char *argv[]){ + printf("app run\n"); + return 0; +} \ No newline at end of file diff --git a/exec/exec.c b/exec/exec.c new file mode 100644 index 0000000..acd03a4 --- /dev/null +++ b/exec/exec.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +extern char **environ; + +int main(int argc ,char *argv[]) +{ + char pwd[1024]; + getcwd(pwd,1024); + printf("master \n"); + printf("path %s\n",pwd); + char path[1024]; + snprintf(path,sizeof(path),"%s/app.bin",pwd); + + char *exec_arg[]={path,NULL}; + char *envp[] = {NULL}; + int err = execve(path,exec_arg,envp); + printf("error happen %d\n",err); + return 0; +} + + +// int main() { + +// char *args[] = {"/bin/ls", "-l", NULL}; +// char *envp[] = {"PATH=/bin:/usr/bin", NULL}; +// execve("/bin/ls", args, envp); +// // 如果 execve 失败,会执行到这里 +// perror("execve failed"); + +// return 1; + +// } \ No newline at end of file diff --git a/exec/run.sh b/exec/run.sh new file mode 100755 index 0000000..21cff57 --- /dev/null +++ b/exec/run.sh @@ -0,0 +1,4 @@ +#!/bin/bash +gcc -o app.bin ./app.c +gcc -o test.bin ./exec.c +./test.bin ./app.bin \ No newline at end of file diff --git a/exec/test.bin b/exec/test.bin new file mode 100755 index 0000000000000000000000000000000000000000..6f45c882e0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