about SPAWN

Hi everybody!

I am trying to use spawn() to create a new process. The thing is, that the process i call by using spawn() starts to run after the calling process finishes running; and what I need is for it to interrupt the calling process, run, and then come back to the calling process to finish running. How can I accomplish that?

Another question… how can I set the priority to the process called with spawn()?

And for the last… does anybody has an example, or can tell me how to use IPC via messages and process creation with spawn()? I want to use the IPC via messages to communicate those processes with each other.

Thanks in advance!

Antonio

Hello Antonio,

  1. int spawnl( P_WAIT …)
  2. setprio() function which changes the priority of thread 1 of process pid to priority prio. If pid is zero, the priority of the calling thread is set

Yuriy

I’m actually using spawnl(P_WAIT,…), and still, the process runs after the calling thread is done running… :s… any ideas why?

Do you mean the following happens?

  1. The child program is loaded
  2. The child program is executed
  3. The child program ends
  4. The parent resumes
  5. Now the child is running again without any good reason

If not, please provide a detailed description.

You are correct.

Hi!

What I’m trying to do, is run a parent process, which initializes a value of a shared memory integer variable numero=10… and then create a child process, which decrements that value by 1 until numero=0, in a for cycle. It’s only that when I run it, i get the following result…

#Value of numero = 10
Starting…
Process was created.


------------- ENTRO-------------

Numero: 9
------------- ENTRO-------------
Numero: 8
------------- ENTRO-------------
Numero: 7
------------- ENTRO-------------
Numero: 6
------------- ENTRO-------------
Numero: 5
------------- ENTRO-------------
Numero: 4
------------- ENTRO-------------
Numero: 3
------------- ENTRO-------------
Numero: 2
------------- ENTRO-------------
Numero: 1
------------- ENTRO-------------
Numero: 0

The first part is printed by the parent process:

Value of numero = 10
Starting…
Process was created.


And the last part is printed by the child process, 10 times inside the for cycle until numero=0…

I call spawnl(P_WAIT,…) after printing “Starting…” at the parent process, so… I would expect the following instead:

#Value of numero = 10
Starting…
------------- ENTRO-------------
Numero: 9
------------- ENTRO-------------
Numero: 8
------------- ENTRO-------------
Numero: 7
------------- ENTRO-------------
Numero: 6
------------- ENTRO-------------
Numero: 5
------------- ENTRO-------------
Numero: 4
------------- ENTRO-------------
Numero: 3
------------- ENTRO-------------
Numero: 2
------------- ENTRO-------------
Numero: 1
------------- ENTRO-------------
Numero: 0

Process was created.


Am I right?, or what should I expect?

Thanks to both of you for your help!! :smiley: it’s really helping me!

Antonio

When a number of processes are using printf more or less at the same time the order of printed strings may be chaotic. Most likely, all works according to the docs, printfs are misleading.

You want to print to stderr or do a fflush(stdout) after each printf.