Interrupted System call error (EINTR) solution for Linux semop waiting signal _c language

Source: Internet
Author: User
Tags documentation semaphore
Error phenomenon: (Semop function call, strerror (errno) output result)
Interrupted system call
Platform: RedHat Linux

The description of the Linux documentation about EINTR is this:
While blocked in this system call, the process caught a signal.
The UNIX documentation [IEEE STD 1003.1-2008] Description of EINTR is like this:
The Semop () function is interrupted by a signal.

Such two sentences if the word is understood literally, is in the process of semop waiting intr signal.
However, the occurrence of errors needs to be resolved, the cause of the error is generally caused by the code written by the programmer.
After debugging the output to locate the problem cause, finally found the problem all:
When SEMOP is waiting for a resource, if at this time a thread in the process uses system to invoke the Shell function, SEMOP returns immediately with the error number EINTR and the error message as above. Don't look at such a small problem, in my system, because of the use of various means to implement IPC (in-process communication), to hit the reason is because a system call is not so simple.

[Because the solution to this problem on the network is not found for the time being, I hope to help others]

This error I searched some posts on Google, and one of my friend once said: Because of the deadlock caused
Because the semaphore itself is preventing deadlocks. I purposely did the experiment, using a mutex variable and a semaphore, and two semaphores, in different order to achieve deadlock, but the system did not appear I expected "interrupted system call", but just wait.

Today, when I read the 1th volume Interface API for UNIX network programming, I saw a sentence that made me understand why this error occurred, The original text reads as follows:
The basic rule for slow system calls is that the system call may return a EINTR error when a process blocking a slow system call captures a signal and the corresponding signal processing function returns. Some cores automatically reboot some of the interrupted system calls. ”
In this case, the slow system call, which refers to a blocking function like accept in the book, and the SEMOP function discussed above, I think should be the same, so when the present EINTR signal, the system call is interrupted and an error is returned, The error number is: EINTR, we can restart our system call from this error number.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.