int create_process(char input[]){
char string[100];
int j = (sizeof(input) / sizeof(input[0]));
char temp[j+1];
int i = 0;
for(i = 0; i <= j; j++){
temp[i] = input[i];
}
temp[j+1] = '\0';
strcpy(string, temp);
pid_t pid=fork();
if (pid==0) {
char *params[4] = {"/bin/ls", "-l",0};
execv("/bin/ls", params);
exit(127);
}
else {
printf("Continuing the parent process");
}
return 0; }
Can anybody tell me what is wrong with my code it gives me segmentation fault core dump program exited with code 139
create_process gets an array of char as input. Ultimately I want to dynamically execute programs based on the input[] char array.
Any help would be highly appreciated. Thanks.
Note: I am using Ubuntu 15.04.
for example if I want to run gedit input would be
input[0] = 'g';
input[1] = 'e';
input[2] = 'd';
input[3] = 'i';
input[4] = 't';