#include "time.h"
int go_ping(char *svrip)
{
int i = 0;
while(i < 2)
{
pid_t pid;
if ((pid = vfork()) < 0)
{
printf("vfork error");
exit(1);
}
else if (pid == 0)
{
if ( execlp("ping", "ping","-c","1",svrip, (char*)0) < 0)
{
printf("execlp errorn");
exit(1);
}
}
int stat;
waitpid(pid, &stat, 0);
if (stat == 0)
{
return 0;
}
sleep(1);
i++;
}
return -1;
}
最后
以上就是独特龙猫最近收集整理的关于Linux C语言ping方法判断是否已经连接网络方法的全部内容,更多相关Linux内容请搜索靠谱客的其他文章。
发表评论 取消回复