Non-blocking version of system()

后端 未结 6 648
傲寒
傲寒 2020-12-09 03:24

I want to launch a process from within my c program, but I don\'t want to wait for that program to finish. I can launch that process OK using system() but that always waits.

6条回答
  •  孤街浪徒
    2020-12-09 03:39

    Why not use fork() and exec(), and simply don't call waitpid()?

    For example, you could do the following:

    // ... your app code goes here ...
    pid = fork();
    if( pid < 0 )
        // error out here!
    if( !pid && execvp( /* process name, args, etc. */ )
        // error in the child proc here!
    // ...parent execution continues here...
    

提交回复
热议问题