diff --git a/hw5/questions.md b/hw5/questions.md index 24701f52bc36a7a016679eb59f5f19cae3d542d3..a917cbb94730862fd892934f03ab96a3fe69adc9 100644 --- a/hw5/questions.md +++ b/hw5/questions.md @@ -25,11 +25,17 @@ In my code, I realized that the chdir() cannot change the directory if it's in a To allow an arbitrary number of piped commands, we can modify like this: typedef struct command_list{ + int num; + cmd_buff_t *commands; + }command_list_t; + command_list_t clist; -clist.commands = malloc(sizeof(cmd_buff_t)*CMD_MAX) + +clist.commands = malloc(sizeof(cmd_buff_t)*CMD_MAX); + Trade-offs: By using this way, we can allow an arbitrary number of piped commands, instead of having a hard limit (like 8; I included a test case about max number of commands). It will be more efficient if we really want to do some complex pipelined executions. However, we need to update the memory allocation when reaching the initial limit. Moreover, we should be careful about memory leak. It's even more complex since we will have to deal with multiple child processes as well as the parent process, instead of a single one. Therefore, it will be harder to avoid some bugs like memory leak or double free.