Where are shell commands executed inside the unix (Minix) source code?

269 views Asked by At

I'm currently learning about operating system kernels and how they are built from the source code (I'm using Minix).

I'm trying to figure out where the shell commands (ls for example) get executed. I know where to locate the ls.c file (src/bin/ls) I'm just not sure where it gets called when the user types it in the terminal.

My goal is to 'hijack' the ls command to accomplish a different result without editing the command file itself ls.c (for example, the ls command now shuts down the computer or echos a string out). In order to do that I need to know where the text from the user gets parsed and the ls command gets executed.

I looked around in the source and I believe it's located inside the process manager (src/minix/servers/pm) however, this was as far as I got before I got lost.

I know this is a very specific question but hopefully I get get it solved.
Thanks in advance

1

There are 1 answers

4
Yuuta Liang On

You are mixing two different questions together: where is the ls binary, and where is its source code. For the former question, you can use which to determine its absolute path. For example, on my FreeBSD box, which ls outputs /bin/ls. However, ls is a compiled binary file, so it cannot be "hijacked" easily without changing its source code and compiling it again, and that is the later question. You had already determined the correct path to ls: src/bin/ls, so you need to modify ls.c according to your needs and compile it, then optionally install it to your system. I am not quite familiar with Minix build system, but you can always consult the Minix documents to know how to install an updated userspace program.