#ifndef SMALLSH_H #define SMALLSH_H // Name: Damian Amerman-Smith // ID: 934-403-184 // Email: amermand@oregonstate.edu #include // Holds required infractructure for implementing "status" and managing background processes struct smallsh { // Necessary infrastructure for implementing "status" bool use_status; // Determines if the last foregrounded process via a status or a signal int exit_status; // Holds the last foreground exit status int term_sig; // Holds the last foreground termination signal // Linked-list of backgrounded processes that get waitpid(...WNOHANG)-ed // before each terminal prompt struct process* head_proc; struct process* tail_proc; int num_background; // Amount of processes held in the background //Holds most recently forked process for use by catch_children() struct process* child; bool foreground_only; // Ignores requests to background processes }; // Holds process info for management by parent shell // Backgrounded process are held in a linked list by smallsh struct until // finishing execution struct process { pid_t pid; // This process's Process ID struct Command* command; // The command the process is to execute struct process* next; // Pointer for linked-list functionality }; // Holds the details of a command that get passed to child processes struct Command { char* command; // Holds the first key term of a command int argc; // Number of arguments char** argv; // Array of arguments bool input_redirect; // Determines if stdin or input_file is used bool output_redirect; // Determines if stdout or output_fle is used char* input_file; // Filepath of input char* output_file; // Filepath of output bool backgrounded; // If ran in background (true) or shell waits for it (false) }; // Function declarations for smallsh.c struct smallsh* create_shell(); // Initializes shell struct struct process* create_process(struct Command* command); // Initializes process struct bool run_process(struct smallsh* smallsh, struct process* process); // Forks off child processes to run tasks, // tracking backgrounded children void add_to_background(struct smallsh* smallsh, struct process* process); // Adds a new backgrounded process to smallsh's backlog void delete_command(struct Command* command); // Frees allocated memory within a command void delete_process(struct process* process); // Frees allocated memory within a process char* get_substring(char* input, int beginning, int length); // Helper function to replace instances of "$$" with the // process's PID struct Command* parse_command(char* input); // Parses incoming text into the command given // To silence compilation warnings char* strtok_r(char* str, const char* delim, char** saveptr); pid_t waitpid(pid_t pid, int* status, int options); int kill(pid_t pid, int sig); char* itoa(int value, char* string, int radix); #endif