Question

  • Creator
    Topic
  • #2144139

    How does Bash interact with the OS?

    by marcussteyn3217 ·

    Tags: 

    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?

You are posting a reply to: How does Bash interact with the OS?

The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our Community FAQs for details. All submitted content is subject to our Terms of Use.

All Answers

  • Author
    Replies
    • #2423363

      Bash’s Working

      by smith_j100 ·

      In reply to How does Bash interact with the OS?

      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.

    • #4002778

      Reply To: How does Bash interact with the OS?

      by Johnharper2020 ·

      In reply to How does Bash interact with the OS?

      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

Viewing 1 reply thread