I saw the code(read, write system call) that handling EINTR error. I understood interrupt occur in two cases. First, it occur every time quantum for schedule. Second, it occur by signal. But everyone in stackoverflow said just signal case only.
So, My question is that EINTR is returned just by signal? or returned by something else?
Since you mention read
and write
, I'll assume you're referring to POSIX-compliant operating systems and answer for those. As jwdonahue has pointed out, it may be different for different functions and operating systems.
A return value of EINTR
means that the function was interrupted by a signal before the function could finish its normal job. The signal itself may or may not have been caused by an interrupt. Let me elaborate, because the terms "interrupt", "signal" and "interrupted" are subtle.
A signal is simply a particular kind of inter-process communication. It allows the kernel to interrupt the execution of processes and therefore, processes to interrupt each other.
An interrupt, on the other hand, is a lower level, often hardware related phenomenon that originates in the processor. In POSIX environments an interrupt is often turned into a signal by the kernel and sent to relevant processes.
So EINTR
means a signal was received. The signal caused the process to be "interrupted" (not to be confused with an interrupt). The signal may or may not have been caused by an underlying interrupt. For example, SIGSEGV
and SIGBUS
are caused by interrupts while SIGINT
(confusingly enough) is caused by software - generally when a Ctrl-C is sent to the terminal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With