首页 > 解决方案 > 如何从 ac 程序并行执行脚本

问题描述

我想从 ac 程序中执行一个脚本,我希望它应该并行运行。所以为此我写了这段代码。

#include <stdio.h>
main()
{
      pthread_t hwdiagT;
     if(pthread_create(&hwdiagT, NULL, &hwdiagScriptExecution, NULL) == ERROR)
    {
          printf("%s():pthread_cretation failed for hwdiag script execution",__func__);
    }

}

void *hwdiagScriptExecution()
{
/* run diags after rpd hw is up*/
    FILE *pp;
    pp=popen("/usr/bin/hwdiag allquick", "w");
    if ( pp == NULL ) {
        printf("ERROR: Couldn't run hardware diagnostics.");
    }
    else {
        pclose(pp);
    }
    return NULL;
}

对于并行执行,我尝试将脚本放在一个线程中,但似乎它不起作用。看起来这个线程被阻塞,直到整个脚本执行。有什么方法可以实现脚本的这种并行执行。

标签: c

解决方案


推荐阅读