Shell Processes   «Prev  Next»
Lesson 1

Unix Processes and Shells

This module covers basic information about how shell scripts are executed on a UNIX system. Subsequent modules in this course will focus on the programming aspects of the shell. Before we begin those modules, we will look at the difference between using the shell as an interactive command interpreter and using it as a programming language. We will also examine techniques available for running a shell script and go over what processes are started when you run the shell using the various techniques.
The most current version of Ubuntu Linux is Ubuntu 22.04.2 LTS (Jammy Jellyfish). It was released on April 21, 2022, and will receive security updates and support until April 2025. Ubuntu 22.04.2 LTS is a Long-Term Support (LTS) release, which means it is designed to be used for a longer period of time than the regular releases. LTS releases are supported for five years for both desktop and server versions.
Here are some of the new features in Ubuntu 22.04.2 LTS:
  1. GNOME 42 desktop environment
  2. Linux kernel 5.15
  3. New hardware support, including the latest Intel and AMD processors
  4. Improved performance and security

Determine Login Shell

To determine the login shell in Ubuntu 22.04, you need to utilize specific commands in the terminal. Follow the instructions below to identify the current user's login shell:
  1. Open Terminal: You can open the terminal by pressing Ctrl + Alt + T or by typing terminal into the search bar and clicking on the Terminal application.
  2. Execute the following command:
    echo $SHELL
    

The echo $SHELL command prints the value of the SHELL environment variable. The SHELL variable typically holds the path of the default login shell. The output of the command will likely be something similar to /bin/bash, /bin/sh, /bin/zsh, or /usr/bin/fish, depending on your default shell. To determine the login shell for a specific user, you can use the following command:
getent passwd <username>

Replace <username> with the name of the user whose login shell you want to determine. The getent command displays entries from databases supported by the Name Service Switch libraries, which are configured in /etc/nsswitch.conf. The passwd database contains user account information. The output will be a colon-separated line with seven fields. The seventh field is the user's login shell. For example, an output might look like this:
john:x:1001:1001:John Doe,,,:/home/john:/bin/bash

In this case, /bin/bash is the login shell for the user named "john". Please note that you need to have the appropriate permissions to execute these commands, especially when trying to access other user information. If you are having trouble, consider prefacing the commands with sudo to execute them with superuser permissions, like so: sudo getent passwd <username>.


Learning Objectives

In this module, the following will be discussed:
  1. Determine your login shell
  2. Run a shell interactively
  3. Run a shell through a script
  4. Describe the relationship between parent and child processes
  5. Run a shell script using three different techniques

Processes and Process ID

An executing instance of a program is called a process. Some operating systems use the term task to refer to a program that is being executed. The UNIX System guarantees that every process has a unique numeric identifier called the process ID. The process ID is always a non-negative integer.
The program in the figure below prints its process ID.
#include "apue.h"
int
main(void){
 printf("hello world from process ID %ld\n", (long)getpid());
 exit(0);
}

SEMrush Software 1 SEMrush Banner 1