
谁帮我在linux下用c编程写段程序 万分感谢!
程序功能:监控apache2程序运行如果apache2被关闭执行/etc/init.d/apache2start...
程序功能: 监控apache2程序运行 如果apache2被关闭 执行/etc/init.d/apache2 start
展开
1个回答
展开全部
为什么不用脚本呢?脚本既方便,又容易修改
提供一个shell脚本的思路:
apache2运行时会产生某个文件,关闭apache2某个文件又消失
通过
#...
if [ -e /...(某个文件的路径) ];then
exec /etc/init.d/apache2 start
fi
#...
如果用C的话也行,只不过要编译一下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp;
//打开文件,这个文件和上面一样
//判断这个文件是否为空(这里要小心点)
if(/*/...*/){
system("exec /etc/apache....");
}
else
{/*...*/}
return 0;
}
还有个就是进程间通信,麻烦一点
提供一个shell脚本的思路:
apache2运行时会产生某个文件,关闭apache2某个文件又消失
通过
#...
if [ -e /...(某个文件的路径) ];then
exec /etc/init.d/apache2 start
fi
#...
如果用C的话也行,只不过要编译一下:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp;
//打开文件,这个文件和上面一样
//判断这个文件是否为空(这里要小心点)
if(/*/...*/){
system("exec /etc/apache....");
}
else
{/*...*/}
return 0;
}
还有个就是进程间通信,麻烦一点
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询