Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is EINTR error returned?

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?

like image 622
김민기 Avatar asked Oct 18 '25 21:10

김민기


1 Answers

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.

like image 67
Heath Raftery Avatar answered Oct 21 '25 10:10

Heath Raftery