{"id":21429586,"url":"https://github.com/mayank-02/fsh","last_synced_at":"2026-05-15T23:05:31.983Z","repository":{"id":188402707,"uuid":"251374712","full_name":"mayank-02/fsh","owner":"mayank-02","description":"Fast Shell","archived":false,"fork":false,"pushed_at":"2020-10-19T17:52:08.000Z","size":92,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T08:17:37.758Z","etag":null,"topics":["c","shell","unix","unix-shell"],"latest_commit_sha":null,"homepage":null,"language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mayank-02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-30T17:11:32.000Z","updated_at":"2020-12-21T09:00:01.000Z","dependencies_parsed_at":"2023-08-18T22:02:45.956Z","dependency_job_id":null,"html_url":"https://github.com/mayank-02/fsh","commit_stats":null,"previous_names":["mayank-02/fsh"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Ffsh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Ffsh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Ffsh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mayank-02%2Ffsh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mayank-02","download_url":"https://codeload.github.com/mayank-02/fsh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243940062,"owners_count":20372044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","shell","unix","unix-shell"],"created_at":"2024-11-22T22:18:23.411Z","updated_at":"2026-05-15T23:05:26.948Z","avatar_url":"https://github.com/mayank-02.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=25% src=\"./doc/logo.png\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cimg width=25% src=\"./doc/logo-fsh.png\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\u003e\n\n[![GitHub issues](https://img.shields.io/github/issues/mayank-02/fsh)](https://github.com/mayank-02/fsh)\n![Contributions welcome](https://img.shields.io/badge/contributions-welcome-green.svg)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n\u003c/p\u003e\n\nfsh (Fast Shell) is a simple command interpreter a.k.a job control shell for Unix.\n\n## Installation\n\nFollow following steps to install fsh in your system\n\n```bash\n# Generate Makefile from Makefile.in\n\u003e ./configure\n\n# Use Makefile to build the program\n\u003e make\n\n# Use Makefile to install the program\n\u003e sudo make install\n```\n\nYou can uninstall fsh using\n\n```bash\n# Use Makefile to uninstall the program\n\u003e sudo make uninstall\n```\n\n## Features\n\n+ Prompt having current working directory and username\n\n+ Allows the user to execute one or more programs, from executable files on the file-system,\nas background or foreground jobs\n\n+ Allows for the piping ( | ) of several tasks as well as input ( \u003c ) and output ( \u003e ) redirection\n\n+ Provides job-control, including a job list and tools for changing the foreground/background status of currently running jobs and job suspension/continuation/termination\n\n+ Signals like Ctrl-C and Ctrl-Z\n\n+ Built in commands like `cd`, `exit`, etc\n\n## Built-in commands\n\n+ `cd` - Change directory using `chdir(2)`\n\n+ `jobs` - Prints out the command line strings for jobs that are currently executing in the\nbackground and jobs that are currently suspended, as well as the identifier associated\nwith each command line string by maintaining a queue/stack of jobs\n\n+ `fg` - Pops off the topmost job off the jobs queue using `tcsetpgrp(3)`\n\n+ `bg` - Runs the most recently stopped process in background, reliquishing shell control yet still logging to shell using `tcsetpgrp(3)`\n\n+ `exit` - Exits with a meaningful return code\n\n## Usage\n\n```bash\n╭─foo@bar [/home/foo]\n╰─$ progA argA1 argA2 \u003c infile | progB argB1 \u003e outfile\n```\n\nThe above command should fork `progA` and `progB`, make the input for `progA` come from file `infile`, the output from `progA` go to the input of `progB`, and the output of `progB` go to the file `outfile`.\n\n```bash\n╭─foo@bar [/home/foo]\n╰─$ sleep 10\n```\n\nThe above command will run `sleep` for 10 seconds and run it as a foreground process.\n\n```bash\n╭─foo@bar [/home/foo]\n╰─$ sleep 10 \u0026\n╭─foo@bar [/home/foo]\n╰─$ jobs\n PGID     Status    Command\n[10925]   Running   sleep 10 \u0026\n╭─foo@bar [/home/foo]\n╰─$ Done  PGID [10925]  \"sleep 10 \u0026\"\n╭─foo@bar [/home/foo]\n╰─$\n```\n\nThe above example will run `sleep` for 10 seconds in background. `jobs` lists the process as running. After the process exits, the shell will output the termination message on the screen.\n\n```bash\n╭─foo@bar [/home/foo]\n╰─$ cat\n# Press Ctrl-Z\n╭─foo@bar [/home/foo]\n╰─$ jobs\n PGID    Status    Command\n[11082]  Stopped   cat\n╭─foo@bar [/home/foo]\n╰─$ fg\n```\n\nThe above example will run `cat`. Pressing Ctrl-Z will stop the process, which can be checked by `jobs`. It can be brought to foreground again by `fg`.\n\n```bash\n╭─foo@bar [/home/foo]\n╰─$ exit\n```\n\nThe above command will exit fsh.\n\nA few things to note:\n\n+ A command line with pipes having input of any but the first command is redirected, or if the output of any but the last command is redirected will be treated as if the first command has input redirection and/or the last command has output redirection.\n\n+ A job consisting of piped processes is not considered to have completed until all of its component processes have completed.\n\n## Implementation\n\n+ The shell prints a prompt and waits for a command line.\n\n+ The command line consists of one or more commands and 0 or more arguments for every command separated by one or more spaces and pipes (|). The last command is optionally followed by an ampersand \u0026.\n\n+ The command line is then parsed and broken down into a command table having information like arguments, input/output files or background process/not using a state machine.\n\n+ Using the command table, the shell then creates a child process (using `fork(2)`) to load and execute the program (using `execvp(2)`) for *command*.\n\n+ If command's input/output  is redirected/piped, appropriate opening and closing of file descriptors is done using `dup2(2)`.\n\n+ This child process is made the group leader of a new process group in the session.\n\n+ The shell adds this process group to the job list. The process id (pid) for this job is the pid of the group leader (the new child process).\n\n+ The shell waits for commands it executes as foreground processes, but not for those executed as background processes (using `waitpid(2)` and custom `SIGCHLD` handler).\n\n+ Ctrl-Z generates a `SIGTSTP`. This suspends the processes in the current foreground job using `kill(2)`. If there is no foreground job, it has no effects.\n\n+ Ctrl-C generates a `SIGINT`. This causes the shell to kill the processes in the current foreground job using `kill(2)`. If there is no foreground job, it has no effects.\n\n+ Note: The three states of a job are running or foreground, background, stopped.\n\n## References\n\n1. [Shell lab](https://condor.depaul.edu/glancast/374class/hw/shlab-readme.html)\n\n2. [Implementing a Job Control Shell](https://www.andrew.cmu.edu/course/15-310/applications/homework/homework4/lab4.pdf)\n\n3. [Shell Spells](https://cs.wellesley.edu/~cs240/f15/assignments/shell/shell.html)\n\n4. [GNU - Implementing a shell](https://www.gnu.org/software/libc/manual/html_node/Implementing-a-Shell.html)\n\n5. [The Linux Programming Interface](https://www.man7.org/tlpi/)\n\n6. [FAQs](https://www.andrew.cmu.edu/course/15-310/applications/homework/homework4/lab4-faq.pdf)\n\n## Authors\n\n[Mayank Jain](https://github.com/mayank-02)\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayank-02%2Ffsh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmayank-02%2Ffsh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmayank-02%2Ffsh/lists"}