Capturing PIDs of same process at different instances

Hi,
I'm gonna launch a process from my 'C' code. I'm gonna launch it a few times. I would like to capture the PID of that process each time I launch. I have to copy the each PIDs into a 'C' variable and I have to kill all of them when I exit from the 'C' code.

My requirement is

int pid_var1;
int pid_var2;
int pid_var3;

 system\(launch_pro\);   //Instance 1
 pid_var1 = PID \(launch_pro\); // How do I do this???


 I have to repeat this for all the instances. 

Thanks,

Instead of using system, use fork(). This creates a clone of your process. Check the return value of fork() -- if you got zero, you're the clone. Then exec() into what you want, which will replace the clone with whatever command you exec()ed.

The parent gets the child's PID from fork() instead.

You can kill them with kill(), or wait for them with wait().

I got it. Is there a way to get the PIDs when I use the "system" to launch the process?

system() doesn't work that way. The calling process is suspended until the thing it's calling finishes.

If the thing you're calling creates and forks and backgrounds a process on its own, how to capture that depends entirely on the thing you're running. It may tell you by some means(which we can't predict, not knowing what program) -- or it may not.