Question

How does Bash interact with the OS?

By marcussteyn3217 ·
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?
1 total post (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Answers

Collapse -

Bash's Working

by help1563898615 In reply to How does Bash interact wi ...

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.

Back to Linux Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums