]> pilppa.org Git - libplpha.git/blob - src/launcher.c
07f22ccc7443d464e1d5ebfd6cc15928f8ef2f14
[libplpha.git] / src / launcher.c
1 /*
2  * launcher.c
3  *
4  *  Created on: Sep 14, 2010
5  *      Author: lamikr
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 int launch_new_process(char *param_arr[]) {
13         int ret_val;
14         int child_pid;
15
16         child_pid       = fork();
17         if (child_pid == -1) {
18                 // failed to fork a new process
19                 ret_val = -1;
20         }
21         else if (child_pid == 0) {
22                 // code for launched child process
23                 //execvp(param_arr[0], param_arr);
24                 // first parameter must contain a full path to executable
25                 execv(param_arr[0], param_arr);
26                 printf("Failed to execute\n");
27                 exit(-1);
28         }
29         else {
30                 // code for parent process which launched the child
31                 ret_val = child_pid;
32         }
33         return ret_val;
34 }