Skip to content
Snippets Groups Projects
Commit ef435bb9 authored by Andrew To's avatar Andrew To
Browse files

Edit questions.md

parent 22be39ff
No related branches found
No related tags found
No related merge requests found
......@@ -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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment