Is there a version of the wait() system call that sets a timeout?

前端 未结 3 1578
悲&欢浪女
悲&欢浪女 2020-12-07 02:31

Is there any way to use the wait() system call with a timeout, besides using a busy-waiting or busy-sleeping loop?

I\'ve got a parent process that

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 02:57

    You can use waitpid together with the WNOHANG option and a sleep.

    while(waitpid(pid, &status, WNOHANG) == 0) {
        sleep(1);
    }
    

    But this will be an active sleeping. However I see no other way using the wait type of functions.

提交回复
热议问题