- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我使用 fork 编写一个小脚本时,系统调用返回两次进程(每个进程一次):
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int pid = fork();
if (pid == 0) {
// child
} else if (pid > 0) {
// parent
}
}
如果我用 systemtap 对其进行检测,我只会找到一个返回值:
// fork() in libc calls clone on Linux
probe syscall.clone.return {
printf("Return from clone\n")
}
(SystemTap installes probes on _do_fork
而不是克隆,但这不应该改变任何东西。)
这让我很困惑。几个相关的问题:
_do_fork
code正确地,该过程被克隆在函数的中间。 (copy_process
和 wake_up_new_task
)。后面的代码不应该在两个进程中运行吗?最佳答案
因此,代码必须区分作为父项和子项执行。但是没有这种检查,这已经是一个强烈的暗示, child 一开始就没有执行这段代码。因此,应该寻找一个新的 child 返回的专用场所。
由于代码又大又多毛,人们可以尝试作弊并在 arch-specific 代码中寻找“fork”,这很快就会揭示 ret_from_fork。
通过 -> do_fork -> copy_process -> copy_thread_tls http://lxr.free-electrons.com/source/arch/x86/kernel/process_64.c#L158 设置起点
因此
Why does the syscall only return once?
它不会返回一次。有 2 个返回线程,除了另一个使用不同的代码路径。由于探测器仅安装在第一个上,您看不到另一个。另见下文。
If I understand the _do_fork code correctly, the process is cloned in the middle of the function. (copy_process and wake_up_new_task). Shouldn't the subsequent code run in both processes?
我之前指出这是错误的。真正的问题是让 child 返回与 parent 相同的地方有什么好处。我没有看到任何东西,这会很麻烦(额外的特殊外壳,如上所述)。重申一下:让 child 返回 elsehwere 让调用者不必处理返回的 child 。他们只需要检查错误。
Does the kernel code after a syscall run in the same thread / process as the user code before the syscall?
什么是“系统调用后的内核代码”?如果你是线程X,进入内核,你还是线程X。
关于c - 为什么 _do_fork() 的 kretprobe 只返回一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43277675/
kprobes 和 kretprobes 都允许您对内核地址中的特定指令进行探测。 如果注册一个 kprobe,pre_handler 在实际函数之前执行,post_handler 在实际函数之后执行
我正在尝试使用 kretprobe void *__kmalloc(size_t size, gfp_t flags); 拦截 kmalloc我可以使用 kretprobe 结构的 handler 成
当我使用 fork 编写一个小脚本时,系统调用返回两次进程(每个进程一次): #include #include int main(int argc, char *argv[]) { in
想法是使用argdist来测量napi_poll()的延迟持续时间,它返回已处理的数据包数量(称为工作)。 napi_poll() 的执行延迟与处理的数据包数量之比将以直方图的形式给出处理每个数据包所
想法是使用argdist来测量napi_poll()的延迟持续时间,它返回已处理的数据包数量(称为工作)。 napi_poll() 的执行延迟与处理的数据包数量之比将以直方图的形式给出处理每个数据包所
我正在跟踪各种内核函数和系统调用,并在它们之间建立可用于某些性能分析的模式。 我注意到的一件事是,有时,即使在我的简单测试应用程序中,它启动了一些使用一些互斥锁的线程,我也不会收到对 kretprob
/*kprobe_example.c*/ #define FUNCNAME alloc_file /* Find something better. printk() isnt recommended
我正在编写一个内核模块来监视一些系统调用,如果调用成功,这些系统调用希望将函数参数返回给用户空间(通过 netlink 套接字)。 jprobe.kp.symbol_name = "rename";
我是一名优秀的程序员,十分优秀!