gpt4 book ai didi

c - 强制父进程先运行

转载 作者:行者123 更新时间:2023-12-03 03:22:03 26 4
gpt4 key购买 nike

在我的系统(Opensuse)上,默认情况下,子进程总是在 fork 之后首先执行。还有一些方法可以强制子进程先运行。我想知道有没有办法强制父进程先运行?

最佳答案

可以使用这个方法

pid_t pid = fork();
if (pid == -1)
abort();
else if (pid == 0)
{
raise(SIGSTOP); // stop the child
}
else
{
waitpid(pid, NULL, WUNTRACED); // wait until the child is stopped
kill(pid, SIGCONT); // resume the child
}

关于c - 强制父进程先运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40200279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com