Skip to content
Snippets Groups Projects
Commit db3899b2 authored by Ahmet Rüchan Arican's avatar Ahmet Rüchan Arican
Browse files

status pipe fixed

parent b8807ccc
No related merge requests found
Start testing: Jun 30 14:56 CEST
Start testing: Jul 05 13:52 CEST
----------------------------------------------------------
End testing: Jun 30 14:56 CEST
End testing: Jul 05 13:52 CEST
......@@ -210,7 +210,7 @@ static int executePipe(Command *cmd, int background) {
int pids[cmd->command_sequence->command_list_len];
int pidCounter =0;
int counter = 0;
pid_t pid;
pid_t pid, wpid;
int pfd[cmd->command_sequence->command_list_len - 1][2]; // Pipe file descriptors
for(int i = 0; i< cmd->command_sequence->command_list_len-1; i++){
if (pipe2(pfd[i], O_CLOEXEC) == -1) { // Create the pipe
......@@ -224,7 +224,6 @@ static int executePipe(Command *cmd, int background) {
Process * process = newProcess(-1, -1, command);
pl = appendProcess(process, pl);
pid = fork();
process->pid = pid;
pids[pidCounter++] =pid;
if (pid == 0) {// fork child
if (counter == 0) {
......@@ -276,6 +275,7 @@ static int executePipe(Command *cmd, int background) {
}else{
process->pgid = pids[0];
process->pid = pid;
counter++;
lst = lst->tail;
}
......@@ -293,7 +293,8 @@ static int executePipe(Command *cmd, int background) {
//Überarbeiten
for(int i =0; i< cmd->command_sequence->command_list_len; i++){
waitpid(pids[i], NULL, 0);
wpid = waitpid(pids[i], &status, 0);
updateList(wpid, status);
}
tcsetpgrp(fdtty, shell_pid);
return status;
......
No preview for this file type
......@@ -91,41 +91,35 @@ void printProcessList(ProcessList * processList){
p->isShown = 1;
}
if(p->isRunning){
printf("%d\t%d\t%s\t%s %d\n", p->pid, p->pgid, "running", p->cmd, p->isShown);
printf("%d\t%d\t%s\t%s\n", p->pid, p->pgid, "running", p->cmd);
}else if(WIFEXITED(p->status)){
printf("%d\t%d\texit(%d)\t%s %d\n", p->pid, p->pgid, WEXITSTATUS(p->status), p->cmd, p->isShown);
printf("%d\t%d\texit(%d)\t%s\n", p->pid, p->pgid, WEXITSTATUS(p->status), p->cmd);
}else if(WIFSIGNALED(p->status)){
printf("%d\t%d\tsignal(%d)\t%s %d\n", p->pid, p->pgid, WTERMSIG(p->status), p->cmd, p->isShown);
printf("%d\t%d\tsignal(%d)\t%s\n", p->pid, p->pgid, WTERMSIG(p->status), p->cmd);
}else{
printf("%d\t%d\t%d\t%s\n", p->pid, p->pgid, p->status, p->cmd);
}
processList = processList->next;
}
/* processList = pl;
ProcessList * previous = NULL;
while(processList != NULL){
Process * p = processList->head;
if(p->isShown){
}
previous = processList;
processList = processList->next;
}*/
}
/* if(previous == NULL){
fprintf(stderr, "1: %s\n", p->cmd);
pl = processList->next;
pl->head = processList->next->head;
pl->next = processList->next->next;
previous = pl;
}
fprintf(stderr, "2: %s\n", p->cmd);
free(p->cmd);
free(p);
*/
void updateList(pid_t pid, int status){
ProcessList * list = pl;
while(list != NULL){
if(list->head->pid == pid){
list->head->status = status;
list->head->isRunning = 0;
}else if(list->head->pid == -1){
list->head->pid = pid;
list->head->status = status;
list->head->isRunning = 0;
}
list = list->next;
}
}
......@@ -23,6 +23,7 @@ ProcessList * appendProcess(Process * process, ProcessList * processList);
Process * findPid(pid_t pid);
ProcessList *deleteProcess(ProcessList * processList);
void printProcessList(ProcessList * processList);
void updateList(pid_t pid, int status);
......
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment