diff --git a/smallsh/main.c b/smallsh/main.c index c32abe1..d7a8118 100644 --- a/smallsh/main.c +++ b/smallsh/main.c @@ -2,6 +2,7 @@ volatile sig_atomic_t stop_flag = 0; int stop_msg = 0; +int at_prompt = 0; int main() { @@ -31,10 +32,12 @@ int main() { // Shell Value Grabbing + at_prompt = 1; printf(": "); fflush(stdout); getline_len = getline(&input, &input_size, stdin); input[getline_len - 1] = '\0'; + at_prompt = 0; // Fill in PID for '$$' expand_dollar(input, input_size); @@ -159,6 +162,7 @@ int run_command(char*** array, int num_array) { int f = fork(); pid_t pid; if(!f) { + signal(SIGTSTP, sigstop_handle); // Handle Redirected output if(redirect_o) { int fd = open(redirect_o_str, O_WRONLY | O_CREAT, 0666); @@ -262,6 +266,15 @@ void sigstop_handle() { // Negate flags so that it handles both starting and stopping stop_flag = !stop_flag; stop_msg = !stop_msg; + + if(at_prompt) { + if(stop_flag) + puts("\nEntering Stop Mode: Background Processes Do Not Work (&)\n:"); + else + puts("\nExiting Stop Mode: Background Processes Now Work (&)\n:"); + stop_msg = 0; + } + } void clean_children() { diff --git a/smallsh/node.c b/smallsh/node.c deleted file mode 100644 index 698180c..0000000 --- a/smallsh/node.c +++ /dev/null @@ -1,62 +0,0 @@ - -#include "node.h" - -void append_node(struct node* head, struct node* node_app) { - - if(!head) { - head = node_app; - return; - } - - struct node* temp = head; - - while(temp->node != NULL) { - temp = temp->node; - } - temp->node = node_app; - -} - -struct node* appendv_node(struct node* head, void* data) { - - struct node* node = malloc(sizeof(struct node)); - node->data = data; - node->node = NULL; - - append_node(head, node); - - return node; -} - -int count_nodes(struct node* head) { - - int num = 1; - - if(!head) - return -1; - - struct node* temp = head; - while(temp->node) { - - temp = temp->node; - num++; - } - - return num; -} - -void iterate_nodes(struct node* head, void *func (void*, void*), void* val) { - - if(!head) - return; - - func(head->data, val); - - struct node* temp = head; - - while(temp->node) { - temp = temp->node; - func(temp->data, val); - } -} - diff --git a/smallsh/node.h b/smallsh/node.h deleted file mode 100644 index 71f4d6d..0000000 --- a/smallsh/node.h +++ /dev/null @@ -1,24 +0,0 @@ -#include "stdlib.h" - -#ifndef NODES -#define NODES - -struct node { - struct node* node; - void* data; -}; - -// Appends Node to list -void append_node(struct node*, struct node*); - -// Creates node with value and appends -// Returns node that was created -struct node* appendv_node(struct node*, void*); - -// Counts the number of nodes in a list -int count_nodes(struct node*); - -// Iterates over every node in a list and runs the given function -void iterate_nodes(struct node*, void *func(void*, void*), void*); - -#endif