I am doing a minishell project for college, and I don't know how to execute commands in background. The one thing i know is that i have to use waitpid() and sigaction(), but i don't know how. If somebody would give me a hand with this i will be gratefull. Here is the part of the code that I use, to make use of the minishell commands.
void execute_command_line(command* cmds, int n){
pid_t id,pid;
int status;
id=fork();
if(id==-1){
exit(EXIT_FAILURE);
}
else if(if==0){
execvp(cmds[0] . argv[0],&cmds[0] .argv[0]);
exit(0);
}
else{
pid=wait(&status);
if(pid==-1){
perror("Father: an error has ocurred.\n");
exit(EXIT_FAILURE);
}
else if(pid==id){
printf("Father: the son has ended.\n");
}
}
}