Hi all,
I'm writing a manager application (Linux/C++) that'll spawn 2 instances of a program (myApp). The myApp program needs to stay alive after being spawned (both instances) so a 3rd party program could connect to them thru socket. My problem is at the fork and exec function which I'm not really familiar with yet. Could anyone help to point me in the right direction or maybe enlighten me with the correct usage of fork and exec.
Thanks and regards.
Here's the main part of my manager application (that's supposed to spawn 2 instances of myApp)
I'm writing a manager application (Linux/C++) that'll spawn 2 instances of a program (myApp). The myApp program needs to stay alive after being spawned (both instances) so a 3rd party program could connect to them thru socket. My problem is at the fork and exec function which I'm not really familiar with yet. Could anyone help to point me in the right direction or maybe enlighten me with the correct usage of fork and exec.
Thanks and regards.
Here's the main part of my manager application (that's supposed to spawn 2 instances of myApp)
Code:
------------------------------------------------------------------------------- int main(int argc, char **argv) { int buff; char msg[MAXLINE]; int result; int count = 0; do{ printf("\n1) To bring up myApp: instance 1\n"); printf("2) To bring up myApp: instance 2\n"); printf("Input choice or 0 to exit:"); scanf("%d", &buff); switch(buff){ case 1: if(fork()) wait(0); else { result = execlp("../experiment/myApp","myApp", "1", "8050", (char *)NULL); perror("Result1:"); } break; case 2: if(fork()) wait(0); else { result = execlp("../experiment/myApp","myApp", "2", "8051", (char *)NULL); perror("Result2:"); } break; case 0: break; } }while(buff != 0); return 0; }
Comment