diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..08d9005b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/labs/03/my_terminal b/labs/03/my_terminal new file mode 100755 index 00000000..362e7854 Binary files /dev/null and b/labs/03/my_terminal differ diff --git a/labs/03/my_terminal.c b/labs/03/my_terminal.c new file mode 100644 index 00000000..55cadd42 --- /dev/null +++ b/labs/03/my_terminal.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +int main() { + char command[50]; + int status; + + while (1) { + printf("osh> "); + fgets(command, 50, stdin); + + command[strcspn(command, "\n")] = 0; + + if (strcmp(command, "exit") == 0) { + break; + } + + pid_t id = fork(); + + if (id == -1) { + exit(EXIT_FAILURE); + } else if (id == 0) { + execlp(command, command, NULL); + exit(EXIT_FAILURE); + } else { + waitpid(id, &status, 0); + } + } + + return 0; +} \ No newline at end of file