问题
I am starting a new task using a clone(2)
call.
There used to be CLONE_STOPPED
flag, but it is no longer present in current kernel.
Is there any trick to start a task in a Stopped state (waiting for SIGCONT
to actually run)?
回答1:
You can't, there's no way to do that in recent kernels, not unless you write a kernel module to do that.
You can see how kernel v2.6.32 used to do it in kernel/fork.c (L1449):
if (unlikely(clone_flags & CLONE_STOPPED)) {
/*
* We'll start up with an immediate SIGSTOP.
*/
sigaddset(&p->pending.signal, SIGSTOP);
set_tsk_thread_flag(p, TIF_SIGPENDING);
__set_task_state(p, TASK_STOPPED);
} else {
wake_up_new_task(p, clone_flags);
}
It should be possible (but arguably not trivial?) to write a wrapper function in kernel space to do something similar.
回答2:
The child can send itself SIGSTOP
at the beginning of the executed fn
来源:https://stackoverflow.com/questions/32959016/how-to-fork-a-linux-process-in-a-stopped-state