Notes on problems encountered by linux network programs

Source: Internet
Author: User
Tags usleep
Notes about some problems encountered by linux network programs-general Linux technology-Linux programming and kernel information. The following is a detailed description. I have been writing a network proxy program for linux recently, but the program is often dumped under many users and pressure, so it is depressing. Note the following issues that have not been encountered in windows:

1. Frequent thread opening
When the program frequently opens threads, there may be insufficient memory and threads cannot be opened. Solution: Set an attribute for the thread during the development.
Pthread_attr_t attr;
Pthread_attr_init (& attr );
Pthread_attr_setdetachstate (& attr, PTHREAD_CREATE_DETACHED );
A foreigner also recommended a very good method to call usleep (1) before the creation.

2. send data frequently
When the program frequently calls send to send data, the program will generate core dump. You still don't know how to solve this problem.
"When sending is continuously called, the system may encounter an inexplicable SEGFAULT (indicating that corefile has no information content). In my opinion, the program may flushed the system's socket buffer. So I put usleep (1) behind each send ). This microsecond has played a major role. But the reason is unclear. Maybe this usleep is also a cure. You need to learn more about the system kernel! "
Related Article

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.