{"id":30977278,"url":"https://github.com/anvay936/custom-posix-shell","last_synced_at":"2026-05-08T09:32:32.377Z","repository":{"id":312253659,"uuid":"1046732170","full_name":"anvay936/custom-posix-shell","owner":"anvay936","description":"C++20 minishell using POSIX (fork/exec, pipe/dup2, signals). Supports pipelines, I/O redirection, background (\u0026), jobs/fg/bg, readline, and resource limits.","archived":false,"fork":false,"pushed_at":"2025-08-29T10:44:17.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-12T05:44:53.755Z","etag":null,"topics":["cpp","cpp20","linux","minishell","posix","shell","wsl2"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anvay936.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-29T06:17:40.000Z","updated_at":"2025-08-29T10:44:20.000Z","dependencies_parsed_at":"2025-08-29T14:25:02.155Z","dependency_job_id":"a1dfd1aa-bc60-44ba-97c5-a62e35b1806a","html_url":"https://github.com/anvay936/custom-posix-shell","commit_stats":null,"previous_names":["anvay936/custom-posix-shell"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anvay936/custom-posix-shell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvay936%2Fcustom-posix-shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvay936%2Fcustom-posix-shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvay936%2Fcustom-posix-shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvay936%2Fcustom-posix-shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anvay936","download_url":"https://codeload.github.com/anvay936/custom-posix-shell/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anvay936%2Fcustom-posix-shell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32774783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cpp","cpp20","linux","minishell","posix","shell","wsl2"],"created_at":"2025-09-12T05:03:49.842Z","updated_at":"2026-05-08T09:32:32.370Z","avatar_url":"https://github.com/anvay936.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom POSIX Shell\n\nA small Linux-like shell built in C++ that supports pipelines, I/O redirection, background execution, history, minimal job control, and resource limits — implemented with POSIX primitives.\n\n## Features\n- **Built-ins:** `cd`, `pwd`, `echo`, `exit`, `export`, `unset`, `env`, `jobs`, `fg`, `bg`, `limit`\n- **Pipelines:** `cmd1 | cmd2 | cmd3`\n- **I/O redirection:** `\u003c`, `\u003e`, `\u003e\u003e`\n- **Background execution:** `\u0026` (e.g., `sleep 5 \u0026`)\n- **History \u0026 line editing:** GNU Readline (↑/↓, Ctrl+R)\n- **Command separators:** `;` (e.g., `echo one ; echo two`)\n- **Signals:** Ctrl-C interrupts foreground jobs without killing the shell\n- **Startup config:** reads `~/.minishellrc` on launch\n\n## Prerequisites\n```bash\nsudo apt update\nsudo apt install -y build-essential g++ make libreadline-dev\n```\n\n## Build and Run\n```bash\nmake run\n```\n\n## Examples\n```bash\n# basics\npwd\necho hello \u003e out.txt\ncat out.txt | tr a-z A-Z\n\n# pipelines \u0026 redirection\nls -l | grep '^d' | wc -l\ntr a-z A-Z \u003c out.txt \u003e\u003e OUT.txt\n\n# background \u0026 jobs\nsleep 10 \u0026\njobs\nfg %1\n\n# environment\nexport GREETING=hello\nenv | grep GREETING\nunset GREETING\n\n# resource limits (CPU seconds / address space MB)\nlimit cpu 1\npython3 -c \"while True: pass\"            # gets killed by CPU limit\nlimit mem 64\npython3 -c \"x='x'*(200*1024*1024)\"       # MemoryError under 64 MB\n\n# separators\necho one ; echo two ; ls -1 | wc -l\n```\n\n## How It Works \n\n- **REPL → Tokenize → Parse → Execute.**  \n  Input is tokenized (words, quotes, operators), parsed into a pipeline of stages (with any `\u003c`, `\u003e`, `\u003e\u003e`, `\u0026`), then executed.\n\n### Pipelines\n- For **N** stages, create **N−1** pipes.\n- `fork()` per stage; `dup2()` pipe ends to `STDIN`/`STDOUT`; `execvp()` the program.\n\n### Redirection\n- `open()` the file; `dup2()` to `STDIN`/`STDOUT` before `execvp()`.\n\n### Built-ins\n- If a built-in runs **alone** (no redirection/pipes), execute **in-process**.\n- If part of a **pipeline/redirection**, run the built-in **in the child** and flush (`write()`/`std::cout.flush()`) to avoid stdio buffering issues.\n\n### Background (`\u0026`)\n- Skip `waitpid()` and return the prompt immediately.\n- Track the last stage’s PID in a minimal **jobs table**.\n- `jobs` lists: `[id] pid  Running/Done  \u003ccmd\u003e`  \n- `fg %id` waits for that job in the foreground.  \n- `bg %id` sends `SIGCONT` (useful if you manually `STOP` a job).\n\n### Signals\n- Shell installs a `SIGINT` handler so **Ctrl-C** prints a newline and leaves the shell alive.\n- Children restore default handlers so **Ctrl-C** interrupts foreground jobs.\n\n### Limits\n- `limit cpu \u003csec\u003e` sets `RLIMIT_CPU`.  \n- `limit mem \u003cMB\u003e` sets `RLIMIT_AS`.\n\n### Startup RC\n- On launch, the shell reads lines from `~/.minishellrc` and executes them.  \n  Lines starting with `#` are treated as comments and ignored.\n\n## Project Structure\n\nminishell/\n├─ src/\n│  └─ main.cpp\n├─ include/         # (optional headers)\n├─ bin/             # build output\n├─ Makefile\n└─ README.md\n\n\n## Make targets\n\nmake run — build \u0026 run bin/minishell\n\nmake — build only\n\nmake clean — remove bin/\n\n## Known limitations (v1)\n\n- No logical operators \u0026\u0026 / || (use ; to chain).\n\n- No glob expansion (e.g., *.txt), no heredoc \u003c\u003c.\n\n- Minimal job control (basic jobs/fg/bg; no terminal process group/Ctrl-Z integration).\n\n- No advanced shell features (subshells, command substitution, arrays, functions, aliasing, etc.)\n\n## Troubleshooting\n\n- pwd/echo seem silent: fixed by using unbuffered write() in built-ins and/or std::cout.setf(std::ios::unitbuf).\n\n- cat out.txt | tr a-z A-Z says syntax error: ensure your tokenizer collapses accidental || into | and your parser accepts a stage with either argv or redirection before |.\n\n- python3 - \u003c\u003c'PY' fails: heredoc \u003c\u003c not supported in v1; use python3 -c \"\u003ccode\u003e\" or a pipe.\n\n- On WSL: build/run in your Linux home (~/minishell) for best I/O performance; copy to Windows only for backup.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanvay936%2Fcustom-posix-shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanvay936%2Fcustom-posix-shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanvay936%2Fcustom-posix-shell/lists"}