如何在Stopped状态下派生Linux进程? [英] How to fork a Linux process in a Stopped state?

查看:67
本文介绍了如何在Stopped状态下派生Linux进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 clone(2)调用开始新任务.

I am starting a new task using a clone(2) call.

曾经有 CLONE_STOPPED 标志,但是它在当前内核中不再存在.

There used to be CLONE_STOPPED flag, but it is no longer present in current kernel.

是否有任何技巧可以在已停止"状态下启动任务(等待 SIGCONT 实际运行)?

Is there any trick to start a task in a Stopped state (waiting for SIGCONT to actually run)?

推荐答案

您不能,在最近的内核中无法做到这一点,除非您编写内核模块来做到这一点.

You can't, there's no way to do that in recent kernels, not unless you write a kernel module to do that.

您可以在内核/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.

这篇关于如何在Stopped状态下派生Linux进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆