If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below. ** If you are logged in, most ads will not be displayed. **

Executing number of processes from a process

Hi,
I wanted to know some method to run an executable from a process i.e. run one process using another.suppose there are 2 process which i need to monitor on 1.ProcessA and 2.ProcessB.
I need to check in another program called Main,whether ProcessA is running or not if it is running then move forward to check for ProcessB else if ProcessA is not running then Execute ProcessA and then Move forward to ProcessB.
I searched google and i found exec(),system() etc, but i dont want to use exec().and using system() my program waits for ProcessA to complete.so in need Main to start a process and move forward to check for another process w/o waiting for a process to be completed.
Or can i schedule a process by myself to run in my code.how to do this?
One more question:How to make a process run when we restart our machine?

I need to check in another program called Main,whether ProcessA is running or not
if it is running then move forward to check for ProcessB
else if ProcessA is not running then Execute ProcessA and then Move forward to ProcessB.

So you "move forward" whether ProcessA runs or not.
Which would mean, that ProcessA and ProcessB are independent.
If so,
- write a init script for each. This will start them at boot time
- monitor them individually. How to do that depends on the processes. Maybe via pid, or check ports, or actually run tests with expected results.

Hey Thanks for your reply.Actually I can check them using there pid in my Main program but i dont know how to start them.i dont know how to write a script to start them.And yes these two processes are independent.Can u post a script code to start a process called "ProcessA"?I will be much helpfull.And can i run a script using a c program?

Yes, most probably with exec(), as you already know.
However, as you intend to restart these processes from your main application you would also need to develop and implement some monitoring, cleanup and starting code.

This is possible and depending on the usecase maybe even neccessary.
However, if processA and processB are independent, then maybe a different approach is to "outsource" the starting and monitoring to initscripts and a monitoring solution.

As an example:
apache and mysql are two processes.
They do depend on each other for about any dynamic website.
But neither mysql is starting and monitoring apache nor vice versa.
They both have their respective initscripts and are (hopefully) monitored by e.g. nagios or xymon.

But your usecase might be different.
Are ProcessA and ProcessB quite similar in purpose, maybe sharing data/config, and you need a way to govern them?
Then have a look at gearman.

Basically i am writing a server code.and i am having 10 processes which are listening on different ports.server code communicates with these processes and these processes are connected to client.So a program is needed to start a process if it is not running as these process are important to be running all the time.

Hmm, I would probably stick to the init script approach.
10 independent init scripts, one for each process.
Init scripts are the standard way of handling daemon startup/stop.

As for the availability part:
Monitoring is a definite requirement.
If a process crashes, then chances are that a simple restart might not fix it.
So you need to graph and log these processes and inform someone in case of a downtime.

If you go for high availability:
One way would be to have multiple machines with these 10 processes each.
Then a pair of redundant loadbalancers in front to distribute requests to only healthy nodes.

Of course, multiple machines then have consequence on data integrity and synchronisation.