Return-Path: william@bourbon.usc.edu Delivery-Date: Mon Sep 8 18:53:08 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 m891r8N1029713 for ; Mon, 8 Sep 2008 18:53:08 -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 m891qEdI012321 for ; Mon, 8 Sep 2008 18:52:14 -0700 Message-Id: <200809090152.m891qEdI012321@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: dynamic array for pid list Date: Mon, 08 Sep 2008 18:52:14 -0700 From: Bill Cheng Someone wrote: > I created a static array of size 50 for handling the child > processes but I am having trouble managing the "int pid_list[50]" > list > > Whenever I create a child process, I increment a global counter > (and add the pid to the pid_list) in the server to reflect this > and so when I break out of my "forever" loop to handle a server > timeout. I try to decrement this global counter. Then I parse the > list to remove the pid from this list. I use a temporary array to > store the new pid_list but i get errors assigning this (address > of) new list temp (smaller pid list) as my pid list. > > Any other suggestions to do this? I know you mentioned the > dynamic array but that seemed to require realloc() each time and > I'm not sure it's a better implementation anyways. You can also use a linked list. By the way, just because you have a dynamic array, it doesn't mean that you have to call realloc() every time. You can increase its size, when needed, by 50 objects at a time. > I was also worried about mutex for the global pid counter set in > the main server program that I am modifying in a SIGCHLD handler. > Should we handle this? You can use sigprocmask() to make sure that you won't get into a deadlock situation. Please note that sigprocmask() can only be used if you use child processes. If you use child threads, you should use pthread_sigmask(). -- Bill Cheng // bill.cheng@usc.edu