Code Monkey home page Code Monkey logo

exam-rank-04-microshell's Introduction

exam-rank-04-microshell

Assignment name : microshell

Expected files : *.c *.h

Allowed functions:

  • malloc, free, write, close, fork,
  • waitpid, signal, kill, exit, chdir,
  • execve, dup, dup2, pipe, strcmp, strncmp

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.

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

Hints:

Do not leak file descriptors!

exam-rank-04-microshell's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.