Question Locked

How does Bash interact with the OS?

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I've been reading explanations about Bash and it's role in the typical Linux environment. Seems like it acts as an interface between system functions, such as file system manipulation, between the OS and the user. But, then, what is Bash using? Is it calling functions defined in the kernel in C or C++? If I were to, say, write a shell language, what resources would describe how to interact with the Linux end? Do all shells (fish, zsh) use the same API to interact with the OS, or are there more layers to it?

2 replies

by smith_j100

To change working directories, Bash executes the chdir system call, which changes the working directory of the calling process. The working directory is inherited by child processes.

To execute a program, Bash calls fork (or maybe vfork or some other variant), which creates a new “child” process that is nearly a copy of the original “parent” one. This child process then makes the execve system call, which replaces its own program with the program requested. Then Bash calls some version of the system call wait in order to wait until the child process terminates.

The reality is more complicated than this, since Bash also has to have some way of executing processes in the background, in subshells, and so on. It’s impossible to describe all of this in a single answer here.

by Johnharper2020

Bash (Bourne Again Shell) is the free and enhanced version of the Bourne shell distributed with Linux and GNU operating systems. Bash is similar to the original, but has added features such as command-line editing.

Regards,
John

This discussion is closed to new replies.