-- SeokchangRyu - 14 Feb 2007

I will explain how to run multi processes with a simple example.

This example comes from the source code of Dexter arm controller. So, I used some existing classes or programs for creating, starting and terminating a child process. They are DML_child and DML_timer . And you also have to add the isr_process program for the inter-process communication.

  • multiProcessesExample:
    childprocess.jpg

As you can see in the above figure, this example is to execute process A, B and C concurrently. Process A and B have different frequencies, 1000 Hz for process A and 60 Hz for process B. On the other hand, C does not have timer and will be executed just one time at the end of every while loop of process A.

These are the simple explanations for the used code.

CHILD A : Create a child process whose ID is A.

TIMER A_timer : Create a timer, A_timer.

Receive (timer) : Wait for the message from a defined timer

Receive (proxy) : Wait for the message that kick ( ) is called.

A.sendInfMsg ( ) : Start process A. If A has its own timer, this is just what you need to do for running process A.

A.kick ( ) : Run process A when A process do not have its own timer.

A.kill ( ) : Terminate process A.

1. Created master and child processes, and their ID should be same as the name of its program file. In this example, I created master process and child process A, B, and C.

2. If you need a timer for a process, you should define the timer as any integer value from 1Hz to 1000Hz. I will run process A at the rate of 1000Hz and B at the rate of 60Hz.

3. Started process A using sendInfMsg ( ) function, which runs at the rate of 1000Hz. Receive ( ) function is used to wait for the message from the timer. Started process B which runs at the rate of 60Hz.

4. Process C is called. But in this time, just initialization_C ( ) function is executed because of the receive function in the while loop of process C. This receive function is waiting for the message that kick ( ) is called.

6. At the end of the while loop in process A, process C is called using kick ( ) function. So, the while loop in process C is executed just one time.

7. If it is requested to finish this program, you have to terminate process B and C which are child processes of process A using kill ( ) function.

8. Then terminate process A in mater process

Please check the exact function or class name in the

‘/dexter/master/master.cpp’ (correspond to Master process),

‘/dexter/dex_driver/dex_driver.cpp’ (correspond to process A),

‘/dexter/dex_tactile/dex_tactile.cpp’ ( correspond to process B) and

‘/dexter/dex_control/dex_control.cpp’ (correspond to process C) file.

 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback