-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9a1d30
commit e0adc73
Showing
34 changed files
with
3,393 additions
and
753 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "bg.h" | ||
#include "../utils/core.h" | ||
#include "../utils/jobs_core.h" | ||
#include "../utils/string_utils.h" | ||
#include <signal.h> | ||
#include <unistd.h> | ||
|
||
int bg(const command_without_substitution *cmd) { | ||
if (cmd->argc != 2) { | ||
print_error("bg: incorrect number of arguments\n"); | ||
return COMMAND_FAILURE; | ||
} | ||
if (strlen(cmd->argv[1]) < 2 || cmd->argv[1][0] != '%') { | ||
print_error("bg: invalid job reference\n"); | ||
return COMMAND_FAILURE; | ||
} | ||
if (!is_integer(cmd->argv[1] + 1)) { | ||
print_error("bg: invalid job reference"); | ||
return COMMAND_FAILURE; | ||
} | ||
unsigned job_number = atoi(cmd->argv[1] + 1); | ||
|
||
int job_placement = get_jobs_placement_with_id(job_number); | ||
if (job_placement == -1) { | ||
print_error("bg: %: invalid job id"); | ||
return COMMAND_FAILURE; | ||
} | ||
pid_t pgid = jobs[job_placement]->pgid; | ||
killpg(pgid, SIGCONT); | ||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef BG_H | ||
#define BG_H | ||
|
||
#include "../parser/parser.h" | ||
|
||
int bg(const command_without_substitution *); | ||
/* Relaunches the job specified in the command argument in the background */ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "fg.h" | ||
#include "../utils/core.h" | ||
#include "../utils/jobs_core.h" | ||
#include "../utils/string_utils.h" | ||
#include <signal.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
#include <unistd.h> | ||
#include <wait.h> | ||
|
||
int fg(const command_without_substitution *cmd) { | ||
if (cmd->argc != 2) { | ||
print_error("fg: incorrect number of arguments\n"); | ||
return COMMAND_FAILURE; | ||
} | ||
if (strlen(cmd->argv[1]) < 2 || cmd->argv[1][0] != '%') { | ||
print_error("fg: invalid job reference\n"); | ||
return COMMAND_FAILURE; | ||
} | ||
if (!is_integer(cmd->argv[1] + 1)) { | ||
print_error("fg: invalid job reference"); | ||
return COMMAND_FAILURE; | ||
} | ||
unsigned job_number = atoi(cmd->argv[1] + 1); | ||
|
||
int job_placement = get_jobs_placement_with_id(job_number); | ||
if (job_placement == -1) { | ||
print_error("fg: %: invalid job id"); | ||
return COMMAND_FAILURE; | ||
} | ||
|
||
int status; | ||
job *j = jobs[job_placement]; | ||
pid_t pgid = j->pgid; | ||
tcsetpgrp(STDERR_FILENO, pgid); | ||
killpg(pgid, SIGCONT); | ||
|
||
waitpid(j->job_process[j->process_number - 1]->pid, &status, WUNTRACED); | ||
|
||
if (WIFSTOPPED(status)) { | ||
j->status = STOPPED; | ||
j->job_process[j->process_number - 1]->status = STOPPED; | ||
print_job(j, false); | ||
} else { | ||
remove_job_from_jobs(j->id); | ||
} | ||
tcsetpgrp(STDERR_FILENO, getpgrp()); | ||
|
||
return SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef FG_H | ||
#define FG_H | ||
|
||
#include "../parser/parser.h" | ||
|
||
int fg(const command_without_substitution *); | ||
/* Relaunches the job specified in the command argument in the foreground */ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.