UNIX Network Programming volume 1 Server programming paradigm 5 preemptible child processes, where parent processes transmit socket descriptors to child Processes

Source: Internet
Author: User

This article is senlie original, reproduced Please retain this address: http://blog.csdn.net/zhengsenlie


1. Only let your process call accept, and then "pass" the accepted connected socket to a sub-process.
In this way, you do not need to provide lock protection because all sub-processes call accept.
2. The parent process must track the idle status of the child process to pass a new socket to the idle child process.


Typedef struct {pid_tchild_pid;/* the ID of the child process */intchild_pipefd;/* the byte stream pipeline descriptor */intchild_status that is connected to the child process in the parent process; /* sub-process status */longchild_count;/* customer count processed by the sub-process */} child; child * cptr;/* array of child structures; calloc 'ed * // * include serv05a */static intnchildren; intmain (INT argc, char ** argv) {intlistenfd, I, navail, maxfd, NSEL, connfd, RC; // navail indicates the number of available sub-processes voidsig_int (INT); pid_tchild_make (INT, Int, INT); s Size_tn; fd_setrset, masterset; socklen_taddrlen, clilen; struct sockaddr * cliaddr; // 0. create a listener socket If (argc = 3) listenfd = tcp_listen (null, argv [1], & addrlen); else if (argc = 4) listenfd = tcp_listen (argv [1], argv [2], & addrlen); elseerr_quit ("Usage: serv05 [


UNIX Network Programming volume 1 Server programming paradigm 5 preemptible child processes, where parent processes transmit socket descriptors to child Processes

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.