Return-Path: william@bourbon.usc.edu Delivery-Date: Wed Sep 3 09:07:29 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m83G7Teu006515 for ; Wed, 3 Sep 2008 09:07:29 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m83G5HO2013721 for ; Wed, 3 Sep 2008 09:05:17 -0700 Message-Id: <200809031605.m83G5HO2013721@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: FW: Question Date: Wed, 03 Sep 2008 09:05:17 -0700 From: Bill Cheng Someone wrote: > My question is: > 1) Lets suppose a child process is created and the parent > process got the child process pid. > And now server process needs to insert that child pid into > the array.but all of the sudden server decides to shutdown. > So as a result the child PID is not in the array. You need to make sure that the child pid goes into your array by programming properly! > In this case how server process will kill that child process > while shutting down gracefully? If you use alarm() to deliver a signal to your main server process at the right time, you need to catch SIGALRM. Please remember that a signal is just a software interrupt. When the signal gets delievered, your server will get interrupted briefly while your interrupt service routine is called. In your interrupt service routine, you should do something simple, such as setting a global variable indicating that it's time to shutdown. Let's stick to your example. You have just forked a child process but you have not stick the child pid into your array. After the signal handler is called and executed, your server code continue to execute and it should put the child pid into your array. Right before you go to the top of your infinite loop and call accept() again, you should check the global flag to see if you should shutdown. In this case, you will break out of the infinite loop, go to your array and send each child process a signal to tell it to quit, and so on. -- Bill Cheng // bill.cheng@usc.edu ----- Original Message ----- From: Bill Cheng Date: Tuesday, September 2, 2008 9:07 pm Subject: Re: FW: Question To: cs551@merlot.usc.edu > Someone wrote: > > > As we need to keep track of the child PIDs , but before > inserting the any > > child pid into the list or dynamic array if the server decide > to shutdown in > > that case what to do with that child process who's id is not > present in the > > array. > > I'm not sure if I'm understanding your question correctly. > > Are you asking about the case where no child process has > ever been created? If that's the case, there is no child > pids to wait for. > > If a child process has been created, why won't you have the > child process's pid? When you call fork(), it returns the > child process's pid and you can stick this pid into the > array you were talking about. > -- > Bill Cheng // bill.cheng@usc.edu >