小编tam*_*ech的帖子

在 Python 中启用 seccomp 后如何干净地退出?

我在一个项目中通过 python-prctl 启用了 seccomp。我不太清楚如何干净地退出 - 结果总是被杀死。

我看到了一些使用 ctypes 或 ffi 尝试引用 libc 的示例,但是如果我希望它们带有 WIFEXITED,它们似乎也有同样的问题。

下面的示例代码。结果总是“我们被杀了”。

def main():
  pid = os.fork()
  if not pid:
    prctl.set_seccomp(True)
    os.write(0, 'Hi\n')

#    os._exit(0)
#    _exit(0)
#    sys._exit(0)
#    return
#    ?!@#(*!  What do?

  endpid, status = os.waitpid(pid, 0)
  print 'Child forked as %d and returned with %d' % (endpid, status)
  if not os.WIFEXITED(status):
    print 'Exitted abnormally'
    if os.WIFSIGNALED:
      if os.WTERMSIG(status) == signal.SIGKILL:
        print 'We were killed to death'
  else:
    print 'Returned with %d' % (os.WEXITSTATUS(status)) …
Run Code Online (Sandbox Code Playgroud)

python seccomp

4
推荐指数
1
解决办法
846
查看次数

标签 统计

python ×1

seccomp ×1