r/C_Programming • • Oct 20 '26

Project I am learning C programming by making this project a unix shell(ForkOff). Looking for a quick code review!

Hey everyone,

Following up on my previous post about my C shell project ForkOff — I wanted to share a bit about my development process and address how AI was used, especially since code authenticity came up in recent reviews!

🤖 AI Involvement

To be 100% transparent: AI was only used to generate and clean up the README.md formatting. And also this post is ai generated.

Every single line of C code, pointer arithmetic, string parsing, and system call logic in the repository was written by hand.

💡 My Approach: Observation & Brute Force

Instead of following step-by-step "how to build a shell" tutorials or asking AI to generate C boilerplate, my approach was pure observation and trial-and-error:

Observe standard Bash: I spent time opening a standard Linux terminal, running commands, testing edge cases (spaces, empty strings, invalid paths), and watching how Bash responded.

Study the core concepts: I read up on POSIX system calls—specifically fork(), execv(), waitpid(), and standard C dynamic memory allocation (malloc, realloc, free).

Brute-force the implementation: I manually wrote the REPL loop, built the string tokenizer, routed built-ins vs. external binaries, and debugged memory leaks/pointer issues step-by-step until the output matched standard shell behavior.

🎯 Next Steps

Now that the core process execution and REPL loop are working, I'm moving on to implementing:

Local I/O redirection (>, <) using dup2().

Chained pipelines (|) using pipe().

Proper signal masks (SIGINT, SIGTSTP) to keep the REPL resilient.

I'd still love any code reviews or feedback on idiomatic C practices in the repo!

GitHub Repository: https://github.com/Anchit3034/ForkOff

Thanks for checking it out!

0 Upvotes

7 comments sorted by

•

u/github-guard Oct 21 '26

⚠️ GitHub Guard: Trust Warning

One or more repositories scored below the threshold (3), but the post was not removed.

Repository: Anchit3034/ForkOff

Score: 1/6

  • ❌ Low Star Count (⭐ 0 / 4 required)
  • ❌ New Repository (under 30 days old)
  • ✅ Licensed under NOASSERTION
  • ❌ No Security Policy
  • ℹ️ Personal Account Repository
  • ℹ️ Unsigned Commits

1

u/Gold-Produce9591 Oct 21 '26

diabolical name

1

u/PowerCreepy4109 Oct 22 '26

Haha Thanks!

1

u/github-guard Oct 21 '26

⚠️ GitHub Guard: Trust Warning

One or more repositories scored below the threshold (3), but the post was not removed.

Repository: Anchit3034/ForkOff

Score: 1/6

  • ❌ Low Star Count (⭐ 0 / 4 required)
  • ❌ New Repository (under 30 days old)
  • ✅ Licensed under NOASSERTION
  • ❌ No Security Policy
  • ℹ️ Personal Account Repository
  • ℹ️ Unsigned Commits

1

u/ef3d0c3e Oct 23 '26

I'm a bit late, but here's some of the things I found.

Magic numbers

In comamnd_runner you set a table with capacity of 51: char *table[51]; tokenisation: if(count >= 50) break is where it's enforced. If you ever want to change the size of the array, you'll have two code locations to do it. Perhaps using a constant (e.g DEFINE, static const int) would fit better, or pass the size of the array when calling tokenisation.

Now bash for instance enforces a maximum number of arguments for commands, but it's a way bigger number (65536 if I record correctly). But 50 feels like an arbitrary low value.

Threads

In main, in switch cases echo, type, and default you create a thread and instantly join it. The instant join means the thread doesn't run concurrently with your main thread or other threads. And your code doesn't seem to be doing something that requires a thread in the first place.

I think it can simply be replaced with a direct call to the thread's runner function. I don't think shells use threads at all (AFAIK at least).

remove_quotes

Your remove quotes uses uint8_t indexes. There's likely no benefit compared to using a size_t or int. The downside is that it can easily overflow. You do something similar in tokenisation, with an int8_t counter. In general, using smaller integer types in variables won't reduce the overall memory usage, because they will still go to a 64-bit/32-bit register.

You should also remove quotes for general arguments: printf "a" displays "a", but there should be no quotes.

Other

Your input look: while (1) inside main never checks for a closed fd. If you press Ctrl-D the fgets() instantly returns with no content read and it creates an infinite loop.

No pipes or command redirection? This is probably because this project is small, however you're already implementing redirection for echo. For commands it's arguably simpler because you can do away with the saving/undoing logic for redirection (redir stay local to the fork).

I wish you good luck with your shell project. Building a shell teaches you really good things about UNIX, C, syscalls and trying to make a reliable program.