]> pilppa.org Git - libplpha.git/blob - src/launcher.c
copy headers with make install, start integrating sysout methods to use libplp
[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 #include <plp/log.h>
13
14 int launch_new_process(char *param_arr[]) {
15         int ret_val;
16         int child_pid;
17
18         child_pid       = fork();
19         if (child_pid == -1) {
20                 // failed to fork a new process
21                 ret_val = -1;
22         }
23         else if (child_pid == 0) {
24                 // code for launched child process
25                 //execvp(param_arr[0], param_arr);
26                 // first parameter must contain a full path to executable
27                 execv(param_arr[0], param_arr);
28                 log_error("Failed to launch new process\n");
29                 exit(-1);
30         }
31         else {
32                 // code for parent process which launched the child
33                 ret_val = child_pid;
34         }
35         return ret_val;
36 }