in reply to Re: How to efficiently manage bunch of processes
in thread How to efficiently manage bunch of processes

That's how I'm doing it right now.

But this way the system behaves like three different, independant apps, this is good - I can stop, start, restart any part of it, and bad - it's three different daemons, and when I hand out maintainance to someone else I need to explain the inner workings of the system - it doesen't behave like a single system to them.

It's a bit like hmm, say, Oracle database, it consist of various important parts, and I would prefer it to behave more like single daemon, like apache webserver.

If I would merge this into single binary, that forks itself to handle various tasks, I would loose ability to easily manage those parts. So this is how it would look like with apps split into two parts:

my $child=fork(); die "Can't fork: $!" unless defined $child; if ($child) { handle_task_one(); } else { handle_task_two(); }
Looks almost ok... but now with three parts:
my $child=fork(); die "Can't fork: $!" unless defined $child; if ($child) { handle_task_one(); } else { my $childschild=fork(); die "Can't fork: $!" unless defined $childschild; if ($childschild) { handle_task_two(); } else { handle_task_two(); } }
Now it becomes unreadable. I got away with it when I created pool of worker 'threads', but with different functions I would prefer my code to look a little better.

Replies are listed 'Best First'.
Re: Re: Re: How to efficiently manage bunch of processes
by castaway (Parson) on Mar 19, 2004 at 13:02 UTC
    So don't merge it. If you look at an Oracle install, or any other sufficiently large software, you'll see it consists of a whole bunch of executables, DLLs and so on. It just has a single Interface, which starts and stops bits as needed. The argument of needing to explain how it runs to someone else isn't really one, if that's how you've designed it, then thats how it is, describe how it works to them.

    It really does sound as if you need one overall script, which runs the others.. Why fork? Why not just run them using system() or similar? (I assume your three parts already have some external method of communicating). That way you get to keep the code in separate, easily managable scripts.

    Alternatively, you don't need to copy all the code into one script to have it run together, using modules and such will keep the actual code separate, but allow it to act as one. Eg. make a module for one part, do 'use Module;' and 'Module::Run();' to get it started ?

    (Forks are yucky, if you ask me ,)

    C.