作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我有一个很好的合作PTRACE_TRACEME
由 PTRACE
处理的子程序包装程序。
问题是如果管理员(或其他)决定 SIGSTOP
子程序,我该如何处理?并拿起SIGCONT
后来,当然。
答案可能是“你不能”?这是PTRACE
毕竟!
我可以看到 PTRACE_LISTEN
(从 Linux 3.4 开始)可以发挥作用,将子程序置于停止状态,但据记载,只有在子程序与 PTRACE_SEIZE
连接时才能工作。 .
我尝试了调用 PTRACE_LISTEN
的琐碎事情当在 PTRACE_TRACEME
在 Group-stop 模式下,我得到了 Old McDonald 错误 - EIO
.
我有一个想法,我可以注入(inject)代码来做 sigsuspend
,但当然这只会暂停子程序的 1 个线程。我必须向每个线程注入(inject)一个信号然后将它们全部停止?然后重启?
或者也许执行重新交付SIGSTOP
已经阻止了他们?在这种情况下,我的 sigsuspend
真的被触发了吗?我想如果另一个线程报告 SIGCONT
我可以直接触发它.
虽然这听起来很有趣,但我想知道我是否错过了 PTRACE
中的一个技巧。文件?也许有办法到达 PTRACE_SEIZE
我缺少的兼容模式?
[更多鱼子酱]
为什么不首先使用 PTRACE_SEIZE 呢?
PTRACE_SEIZE
模式或模拟
SIGSTOP
API 内的行为?
最佳答案
一个例子 PTRACE_SEIZE 下面是模拟 SIGSTOP 行为的测试程序。
#define PTRACE_SEIZE 0x4206
#define PTRACE_SEIZE_DEVEL 0x80000000
static const struct timespec ts100ms = { .tv_nsec = 100000000 };
static const struct timespec ts1s = { .tv_sec = 1 };
static const struct timespec ts3s = { .tv_sec = 3 };
int main(int argc, char **argv)
{
pid_t tracee;
tracee = fork();
if (tracee == 0) {
nanosleep(&ts100ms, NULL);
while (1) {
printf("tracee: alive\n");
nanosleep(&ts1s, NULL);
}
}
if (argc > 1)
kill(tracee, SIGSTOP);
nanosleep(&ts100ms, NULL);
ptrace(PTRACE_SEIZE, tracee, NULL,
(void *)(unsigned long)PTRACE_SEIZE_DEVEL);
waitid(P_PID, tracee, NULL, WSTOPPED);
ptrace(PTRACE_CONT, tracee, NULL, NULL);
nanosleep(&ts3s, NULL);
printf("tracer: exiting\n");
return 0;
}
当上面的代码在没有参数的情况下被调用时,tracee 被从
# ./test-seize
tracee: alive
tracee: alive
tracee: alive
tracer: exiting
# tracee: alive
tracee: alive
tracee: alive
当使用参数调用时,tracee 会从停止状态中被捕获,并且
# ./test-seize
tracee: alive
tracee: alive
tracee: alive
tracer: exiting
# ps -el|grep test-seize
1 T 0 4720 1 0 80 0 - 941 signal ttyS0 00:00:00 test-seize
您可以在
thread 阅读更多内容
关于c - 如何在 ptracer 中处理 SIGSTOP/SIGCONT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63954630/
我是一名优秀的程序员,十分优秀!