linux - nix::sched::clone 在 println 后导致分段错误
问题描述
我正在尝试通过调用手动创建线程clone
。以下代码导致分段错误,但如果我println!
在睡眠前删除代码运行正常。
use nix::sched::{self, CloneFlags};
use std::thread;
use std::time::Duration;
fn task() -> isize {
println!("from inside thread");
thread::sleep(Duration::from_secs(2));
0
}
fn main() {
const STACK_SIZE: usize = 1024 * 1024;
let ref mut stack: [u8; STACK_SIZE] = [0; STACK_SIZE];
let cb = Box::new(|| task());
let flags = CloneFlags::CLONE_VM
| CloneFlags::CLONE_FS
| CloneFlags::CLONE_FILES
| CloneFlags::CLONE_SIGHAND
| CloneFlags::CLONE_THREAD;
sched::clone(cb, stack, flags, None).expect("clone error");
println!("created thread");
thread::sleep(Duration::from_secs(5));
}
附加信息:我的实际目标是试验 linux 命名空间,我想在不同的 uts 命名空间中创建线程,所以我需要能够CLONE_NEWUTS
在调用clone
.
解决方案
推荐阅读
- mit-scratch - 转动 (15) 度刮擦块不起作用
- javascript - css 剪辑路径仅悬停在形状上
- python - 重复元组列表到 csv python
- sql-server - 无法同时通过 VPN 连接到 RDP 和 SQL Server(Azure)
- javascript - 转换 Observable
到可观察的 - python - 使用 python 3 在 windows 中安装 Poppler
- docker - Docker Windows如何在不登录的情况下保持容器运行?
- javascript - 如何从 p2 中删除隐藏的属性()?似乎没有按原样做任何事情
- ruby - 无法通过 rspec 中的测试
- c - 可以在没有堆栈和递归的情况下在 C 中实现快速排序吗?