Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to create one program in C/C++ that will run 2 process. This is my sample code

C++
#include <stdio.h>
#include <stdlib.h>

main()
{
  system("Run process 1");
  system("Run process 2")
  return 0;
} 
;


But the problem is I have to wait the "process 1" to finish first before it can proceed with the second process ("process 2").

What is the best solution so it can run the "process 2" without waiting the "process1" to finish first.

Thanks
Posted
Comments
Ian A Davidson 26-Mar-13 6:36am    
Sorry. I deleted my solution. I should have noted that it says "Linux". I'm afraid I'm rather rusty on Unix.

Use fork[^] to create two threads and start each process via system or exec[^].
 
Share this answer
 
Comments
nv3 26-Mar-13 11:17am    
+5
If you use Visual Studio 2012 (on Windows), it contains the latest language features of C++ which were just added recently. Look up the 'async' keyword.

I see you have 'linux' flagged. I don't know if this is available yet with any linux compiler, but 'async' is still your answer.
 
Share this answer
 
Threads are themselves called light weight processes.
I think, whichever the OS be, solution is to create new threads and let the individual threads execute the different processes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900