From owner-freebsd-questions Mon Mar 2 07:32:54 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA27645 for freebsd-questions-outgoing; Mon, 2 Mar 1998 07:32:54 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from serv01.net-link.net (serv01.net-link.net [205.217.6.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA27640 for ; Mon, 2 Mar 1998 07:32:49 -0800 (PST) (envelope-from wpub1@net-link.net) Received: from ricecake (grxa6-ppp29.triton.net [209.172.2.29]) by serv01.net-link.net (8.8.8/8.6.9) with SMTP id KAA05967; Mon, 2 Mar 1998 10:31:25 -0500 Message-Id: <3.0.3.32.19980302103542.03140e74@smtp.net-link.net> X-Sender: wpub1@smtp.net-link.net (Unverified) X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.3 (32) Date: Mon, 02 Mar 1998 10:35:42 -0500 To: vel@ns.kbsu.ru, questions@FreeBSD.ORG From: Matthew Hagerty Subject: Re: Programming questions In-Reply-To: <199802281638.TAA02990@ns.kbsu.ru> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >Hello people ! > >I have some questions about programming under FreeBSD. > >1. When my process receives signal, what is the simplest and fastest way >to look for PID of process who sent me this signal ? > >2. Is there any way to do accept() or another function like this without >locking while waiting ? For example, my program wants to handle many >network connections at a time without cloning via fork(). I know that >some programs, such as ircd, do this. But how ? > >Pre-thanks. >--- >Eugene L. Vorokov, Kabardino-Balkarian State University, Russia >vel@ns.kbsu.ru >vel@hub.kbsu.ru > You really need to get this book: UNIX Network Programming, Vol 1. Second Edition W. Richard Stevens Prentice Hall PTR ISBN: 0-13-490012-X http://www.kohala.com/~rstevens What you are trying to do is called an "Iterative Server". An iterative TCP server processes each client's request completely before moving on to the next client. The kernel will queue any client requests that arrive while another client is being processed. The number of clients the kernel will queue is passed as a parameter in the listen() command, do a "man listen". If there are no clients to be processed, the accept command blocks. If you want to be able to process multiple clients at the same time, then you will have to fork() or pthread_create() to spawn a child or thread to process the client request. This way the parent can go back to listening for more client requests. See the man page for select() for implementing a non-blocking accept(). But servers that process one client at a time are very susceptible to Denial-Of-Service attacks. Also, non-blocking connects are different across UNIXes and your code will not be very portable. Matthew Hagerty To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message