From owner-freebsd-questions@FreeBSD.ORG Wed Nov 8 11:00:40 2006 Return-Path: X-Original-To: freebsd-questions@FreeBSD.org Delivered-To: freebsd-questions@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C772916A40F; Wed, 8 Nov 2006 11:00:40 +0000 (UTC) (envelope-from nicky@valuecare.nl) Received: from smtp-vbr15.xs4all.nl (smtp-vbr15.xs4all.nl [194.109.24.35]) by mx1.FreeBSD.org (Postfix) with ESMTP id 122B043D5C; Wed, 8 Nov 2006 11:00:30 +0000 (GMT) (envelope-from nicky@valuecare.nl) Received: from [10.0.0.12] (a80-126-182-198.adsl.xs4all.nl [80.126.182.198]) (authenticated bits=0) by smtp-vbr15.xs4all.nl (8.13.8/8.13.8) with ESMTP id kA8B0TYJ056759; Wed, 8 Nov 2006 12:00:30 +0100 (CET) (envelope-from nicky@valuecare.nl) Message-ID: <4551B8D2.3020502@valuecare.nl> Date: Wed, 08 Nov 2006 12:00:34 +0100 From: nicky User-Agent: Thunderbird 1.5.0.7 (X11/20061018) MIME-Version: 1.0 To: Andrew Pantyukhin References: <4551AC4A.2000108@valuecare.nl> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by XS4ALL Virus Scanner Cc: freebsd-questions@FreeBSD.org Subject: Re: Parallel shell scripts. X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Nov 2006 11:00:40 -0000 Andrew Pantyukhin wrote: > On 11/8/06, nicky wrote: >> I have to start 2 processes in the background (running in parallel), >> capture their return codes and after all 4 have completed successfully i >> want to continue with the main script. > > What do you need their return codes for? If you > only want to display them, something like this > might help: > > (/bin/proc1;echo "Proc 1 exited with status $?) & > (/bin/proc2;echo "Proc 2 exited with status $?) & > wait > > In general, retrieving exit statuses of multiple > general is not trivial. I.e. you need some kind of > IPC for that, at least store statuses in some tmp > files and read it back from the main process. > > The whole idea is this. I have to extract two different databases to csv files. One takes about an 1 hour, the other 1.5 hours. The problem is my time window, which is 2 hours. So extracting one after the other is not an option. After both extractions are complete, it should load the csv files into a target database. I figured it would be best to launch the two extraction processes in a child process and just let the main process wait till they are complete. It should then check if the extraction processes completed successfully and proceed to load the data into the target database. My concept script seems to work, but i'm dubious about something. If childprocessA takes longer then childprocessB. The main script is still waiting for childprocessA, while childprocessB has already completed it's run. So, if i am correct, the PID of childprocessB does not exist anymore. So calling 'wait [childprocessB pid]', would it always return 0 or will it still return the actual return code? This just makes me doubt if my concept script is the proper solution for my problem.