|
@@ -12,11 +12,11 @@
|
|
|
#include "error.h"
|
|
|
#include "str.h"
|
|
|
#include "parser.h"
|
|
|
-#include "mysh.h"
|
|
|
#include "execute.h"
|
|
|
#include "ipc.h"
|
|
|
#include "variable.h"
|
|
|
#include "command.h"
|
|
|
+#include "mysh.h"
|
|
|
|
|
|
/* --- Extern --- */
|
|
|
extern Error error;
|
|
@@ -24,6 +24,7 @@ extern pid_t last;
|
|
|
extern int status_cmd;
|
|
|
extern int result_cmd;
|
|
|
extern char base_path[];
|
|
|
+extern pid_list pidlist;
|
|
|
char* cmdlist[] = {
|
|
|
"cd",
|
|
|
"exit",
|
|
@@ -34,6 +35,7 @@ char* cmdlist[] = {
|
|
|
"unset",
|
|
|
"myls",
|
|
|
"myps",
|
|
|
+ "myjobs",
|
|
|
NULL
|
|
|
};
|
|
|
boolean exitsh = false;
|
|
@@ -44,10 +46,18 @@ void ini_pid_list(pid_list* pl) {
|
|
|
pl->last = NULL;
|
|
|
}
|
|
|
|
|
|
-pid_node* add_pid(pid_list* pl, pid_t pid, int job) {
|
|
|
+pid_node* add_pid(pid_list* pl, pid_t pid, int job, char* cmd) {
|
|
|
+ int length;
|
|
|
+ //Creation noeud
|
|
|
pid_node* pn = malloc(sizeof (pid_node));
|
|
|
pn->pid = pid;
|
|
|
pn->job = job;
|
|
|
+ //Copie nom commande
|
|
|
+ length = strlen(cmd) + 1;
|
|
|
+ pn->cmd = malloc(sizeof(char) * length);
|
|
|
+ memset(pn->cmd, 0, length);
|
|
|
+ strncpy(pn->cmd, cmd, length - 1);
|
|
|
+ //Setup chainement
|
|
|
pn->next = NULL;
|
|
|
if (pl->first == NULL) {
|
|
|
pn->prev = NULL;
|
|
@@ -73,6 +83,7 @@ pid_node* search_pid(pid_list* pl, pid_t pid) {
|
|
|
}
|
|
|
|
|
|
void remove_pid(pid_list* pl, pid_node* pn) {
|
|
|
+ free(pn->cmd);
|
|
|
//Si 1er et seul
|
|
|
if (pn->prev == NULL && pn->next == NULL) {
|
|
|
pl->first = NULL;
|
|
@@ -101,6 +112,7 @@ void clean_pid(pid_list* pl) {
|
|
|
pid_node* tmp, * pn = pl->first;
|
|
|
while (pn != NULL) {
|
|
|
tmp = pn->next;
|
|
|
+ free(pn->cmd);
|
|
|
free(pn);
|
|
|
pn = tmp;
|
|
|
}
|
|
@@ -165,6 +177,11 @@ int launch_internal_command(Command* cmd) {
|
|
|
result = myps(cmd->argc, cmd->argv);
|
|
|
return result;
|
|
|
}
|
|
|
+ //myjobs
|
|
|
+ else if (strncmp(cmd->name, cmdlist[9], length) == 0) {
|
|
|
+ result = myjobs(cmd->argc, cmd->argv);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
//Aucune commande
|
|
|
else {
|
|
|
return SHELL_FAIL;
|
|
@@ -368,4 +385,17 @@ int myps(int argc, char** argv){
|
|
|
//Execution
|
|
|
//return exec_file(path, argv);
|
|
|
return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int myjobs(int argc, char** argv){
|
|
|
+ pid_node* pn = pidlist.first;
|
|
|
+ if(pn == NULL){
|
|
|
+ printf("Aucun job\n");
|
|
|
+ return EXIT_SUCCESS;
|
|
|
+ }
|
|
|
+ while(pn != NULL){
|
|
|
+ printf("[%d] %d En cours %s\n", pn->job, pn->pid, pn->cmd);
|
|
|
+ pn = pn->next;
|
|
|
+ }
|
|
|
+ return EXIT_SUCCESS;
|
|
|
}
|