我有一个简单的测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <linux/seccomp.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
void *do_work(void *args) {
prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);
printf("OK.\n");
}
int main() {
pthread_t t;
int ret;
ret = pthread_create(&t, NULL, do_work, NULL);
if (ret != 0) {
printf("Could not create thread, error is %d.\n", ret);
return 1;
}
ret = pthread_join(t, NULL);
if (ret != 0) {
printf("Could not join thread, error is %d.\n", ret);
return 2;
}
printf("Program done.\n");
return 0;
}在Ubuntu 16.04中,这个死锁没有打印任何东西。通过阅读有关seccomp的文档,我不清楚为什么会发生这种情况。为什么会这样呢?SIGKILL不会杀死整个过程吗?
发布于 2016-09-12 23:10:21
原因是printf函数。
如果在程序上运行strace -f (没有prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);行),您将看到创建的线程调用futex系统调用。
seccomp模式禁止对futex的调用,因此线程被终止,因此pthread_join无限期地等待。
如果你用write(1,...)替换printf(),程序将会表现出预期的效果。
发布于 2016-10-19 22:00:55
创建的线程与原始线程具有不同的进程ID (根据strace)。因此,当新线程违反seccomp时,只有它会被杀死。这意味着死锁。
https://stackoverflow.com/questions/38786318
复制相似问题