linux下c/c++程序重启自己
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
在程序自动升级的时候需要自己重新启动自己
示例代码:
点击(此处)折叠或打开
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char **argv)
- {
- char buf[32] = {};
- char *exec_argv[] = { argv[0], buf, 0 };
- int count = argc > 1 ? atoi(argv[1]) : 0;
- printf("Running: %s %d\n", argv[0], count);
- snprintf(buf, sizeof(buf), "%d", count+1);
- sleep(5);
- execv("/proc/self/exe", exec_argv);
- /* NOT REACHED */
- return 0;
- }
zengming@linux-eshv:~/test> g++ main.cpp
zengming@linux-eshv:~/test> ./a.out 1
Running: ./a.out 1
Running: ./a.out 2
Running: ./a.out 3
^C
程序员群:31843264
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献10条内容
所有评论(0)