So right now my shell does everything fine, and this function runs in the background fine. However, I was wondering if there's a way for me to get a report printed to my screen shell when the background job is done.
So if I say:
myshell> sleep 10 &
then 10 seconds later:
myshell> job[blah] finished
Is there a simple way to code this?
Code:
int runInBackground(Command* command, int givenPath)
{
int pid;
char *commandName = command->name;
int status;
if(givenPath == 0)
{
commandName = getCommandPath(command->name);
}
if(commandName == NULL)
{
printf("Command not found.\n");
return 1;
}
pid = fork();
if(pid < 0) //Checks for error
{
printf("Error in the fork process.\n");
return 1;
}
else if (pid == 0) //Child
{
execv(commandName, command->argv);
return 1;
}
else
{
// waitpid(pid, &status, WNOHANG);
}
}