I was trying to understand how SIGSEGV is delivered by the Linux kernel to a process:
https://unix.stackexchange.com/a/257665/346011
我试图理解linux内核如何将SIGSEGV传递给一个进程:https://unix.stackexchange.com/a/257665/346011
From multiple sources, I've read that syscalls are meant to be called from userspace only (as opposed to calling them from kernel space).
我从多个来源了解到,syscall只能从用户空间调用(而不是从内核空间调用)。
So, from what I recall, the only way to generate a signal in Linux is by using the kill syscall. However, if the Linux kernel is not supposed to call syscalls, then how does it kill a process with SIGSEGV?
所以,据我所知,在Linux中生成信号的唯一方法是使用kill系统调用。但是,如果Linux内核不应该调用系统调用,那么它如何使用SIGSEGV杀死一个进程?
更多回答
the only way to generate a signal in Linux from userspace is by using the kill syscall. But the kernel does it directly. After all, the kernel has to implement the kill syscall somehow.
在Linux中从用户空间生成信号的唯一方法是使用kill syscall。但是内核直接做这件事。毕竟,内核必须以某种方式实现终止系统调用。
Signals are delivered at the transition from kernel mode to user mode. If a signal is outstanding, instead of switching to the normal user context the kernel instead switches to the signal handler. The default signal handler terminates the process with an error. A syscall is one reason for being in kernel mode, a memory violation interrupt is another.
信号在从内核模式转换到用户模式时传递。如果信号未完成,则内核不会切换到正常用户上下文,而是切换到信号处理程序。默认信号处理程序终止进程,并返回错误。系统调用是处于内核模式的一个原因,内存违规中断是另一个原因。
优秀答案推荐
我是一名优秀的程序员,十分优秀!