Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/loyc12/microshell42
42 Exam Project
https://github.com/loyc12/microshell42
Last synced: 8 days ago
JSON representation
42 Exam Project
- Host: GitHub
- URL: https://github.com/loyc12/microshell42
- Owner: loyc12
- Created: 2023-06-19T17:55:58.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-13T16:57:08.000Z (3 months ago)
- Last Synced: 2024-08-13T20:13:22.826Z (3 months ago)
- Language: C
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Exam Question
This exam has 1 question, microshell:
- [Microshell.c](https://github.com/pasqualerossi/42-School-Exam-Rank-04/blob/main/microshell.c)
- [Microshell.h](https://github.com/pasqualerossi/42-School-Exam-Rank-04/blob/main/microshell.h)if you can make this code shorter, whilst still readable, let me know!
## Expected Files
- microshell.c
- microshell.h
## Subject Text
Allowed functions:
```
malloc, free, write, close, fork, waitpid, signal, kill, exit, chdir, execve, dup, dup2, pipe, strcmp, strncmp
```## The Program
Write a program that will behave like executing a shell command- The command line to execute will be the arguments of this program
- Executable's path will be absolute or relative but your program must not build a path (from the PATH variable for example)
- You must implement "|" and ";" like in bash
- we will never try a "|" immediately followed or preceded by nothing or "|" or ";"- Your program must implement the built-in command cd only with a path as argument (no '-' or without parameters)
- if cd has the wrong number of argument your program should print in STDERR "error: cd: bad arguments" followed by a '\n'
- if cd failed your program should print in STDERR "error: cd: cannot change directory to path_to_change" followed by a '\n' with path_to_change replaced by the argument to cd
- a cd command will never be immediately followed or preceded by a "|"- You don't need to manage any type of wildcards (*, ~ etc...)
- You don't need to manage environment variables ($BLA ...)
- If a system call, except execve and chdir, returns an error your program should immediatly print "error: fatal" in STDERR followed by a '\n' and the program should exit
- If execve failed you should print "error: cannot execute executable_that_failed" in STDERR followed by a '\n' with executable_that_failed replaced with the path of the failed executable (It should be the first argument of execve)
- Your program should be able to manage more than hundreds of "|" even if we limit the number of "open files" to less than 30.
## Example
for example this should work:
```
$>./microshell /bin/ls "|" /usr/bin/grep microshell ";" /bin/echo i love my microshell
microshell
i love my microshell
$>
```## Hints
- Don't forget to pass the environment variable to execve
- Do not leak file descriptors!## Exam Practice
Practice the exam just like you would in the real exam - https://github.com/JCluzet/42_EXAM