我有一个从C程序内部调用的脚本。我在启动线程之前执行此操作,因为我需要在这些线程启动之前建立ppp链接。我做了以下工作:
int main(){
int ret = 0;
ret = WEXITSTATUS(system("./nbiot_telit_ppp_installer.sh"));
printf("ret = %d\r\n", ret);
// Never gets here after ppp is up
/* Start the threads */
==> starts thread-1
==> starts thread-2
}我尝试在线程1中调用脚本,如下所示:
void *thread1(void *thPtr)
{
int ret = 0;
ret = WEXITSTATUS(system("./nbiot_telit_ppp_installer.sh"));
printf("ret = %d\r\n", ret);
// Never gets here after ppp is up
/* Some aws init code */
while(1){
}
} 关于脚本的成功,我得到了以下结果:
Script /etc/ppp/ip-up started (pid 7771)
Script /etc/ppp/ip-up finished (pid 7771), status = 0x0在上面之后,不会执行超出或低于它的任何代码。仅当脚本终止时才返回。
不管ppp链路是成功还是失败,我希望在c代码中获得"status“值,并根据这个值做出决定。我有在裸机上工作的经验,但对Linux来说还是个新手。如果能从专家那里获得一些关于这个问题的见解和如何实现这一目标的建议,那将是非常棒的。
发布于 2019-10-19 06:00:16
当ppp链路打开时,它执行文件/etc/ppp/ip-up当它关闭时,它执行/etc/ppp/ip-down。如果您在这些文件中放置了某些内容,则可以将其用作标记。
我的ip-up文件:
#!/bin/sh
echo ppp is up > /var/run/ppp-up-flag我的ip-down文件:
#!/bin/sh
rm /var/run/ppp-up-flag现在我的程序可以测试/var/run/ppp-up-flag。
https://stackoverflow.com/questions/58311960
复制相似问题