qq空间刷赞网站推广,网站申请微信登录,网站开发需要会什么软件,苏州门户网站有哪些1.缘起
这个系列会汇集一些临近deadline是最后补救措施#xff0c;以备不时之需。面临项目交付时#xff0c;经常会有一些或大或小的功能项点#xff0c;甚至是bug无法做完。这个时候#xff0c;就需要一些终极补救措施来应对这种不时之需。
第一个工具app_daemon是针对那…1.缘起
这个系列会汇集一些临近deadline是最后补救措施以备不时之需。面临项目交付时经常会有一些或大或小的功能项点甚至是bug无法做完。这个时候就需要一些终极补救措施来应对这种不时之需。
第一个工具app_daemon是针对那些需要长周期运行但是一些内存泄露或者别的资源释放问题迟迟无法解决的情形它叫应用程序看护工具实际运行效果是这样的 [rootlocalhost app_daemon]# ./app_daemon ./test_app real app runing.... real app quited Application scheduling exited. Restarting in 5 seconds... real app runing.... real app quited Application scheduling exited. Restarting in 5 seconds... real app runing.... real app quited Application scheduling exited. Restarting in 5 seconds... 2.编码
//usage: app_daemon app_to_daemons cmd_line [param1 param2 param3...]
//build:gcc app_daemon.c -o app_daemon
#include stdio.h
#include stdlib.h
#include unistd.hvoid runWatchingAppAsSubApp(int argc, char *argv[]) {char new_cmd[2048] {0};int i;int l;for(i0; iargc; i){l strnlen(new_cmd, 2048);if(i0){continue; //i0 is itsself}else{snprintf(new_cmd[l], sizeof(new_cmd)-l-1, %s , argv[i]);}// 替换为您的应用程序启动命令system(new_cmd);}
}int main(int argc, char *argv[]) {if(argc 1){printf(Usage:%s app_to_watch [param1, param2...]\n, argv[0]);return 0;}while (1) {pid_t pid fork();if (pid 0) {// 子进程中运行应用程序runWatchingAppAsSubApp(argc, argv);exit(0);} else if (pid 0) {// 等待应用程序退出int status;waitpid(pid, status, 0);// 延时重启时间单位秒int restart_delay 5; // 5 秒printf(Application scheduling exited. Restarting in %d seconds...\n, restart_delay);sleep(restart_delay);} else {printf(Fork failed\n);return 1;}}return 0;
}附录A 用于测试的一个桩应用
void main(void)
{printf(real app runing....\n);sleep(3);printf(real app quited\n);
}
~