Practical Computing-II

Programming in the Environment

B.W.Gore

March 20, 2015

0. An Introduction

B.W.Gore Programming in the Linux Environment I 25 credits (33.33% weighting)

I About Linux/ environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

B.W.Gore Programming in the Linux Environment I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

B.W.Gore Programming in the Linux Environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment

B.W.Gore Programming in the Linux Environment 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk)

B.W.Gore Programming in the Linux Environment 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence

B.W.Gore Programming in the Linux Environment 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel

B.W.Gore Programming in the Linux Environment 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals

B.W.Gore Programming in the Linux Environment 5. permissions and access control 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes

B.W.Gore Programming in the Linux Environment 6. fork and exec 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control

B.W.Gore Programming in the Linux Environment 7. foreground and background processes

About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec

B.W.Gore Programming in the Linux Environment About The Course

I CMS M.2.2 Practical Computing-II

I 25 credits (33.33% weighting)

I About Linux/Unix environment I Scripting Tools and Languages (like sed & awk) 1. boot-up sequence 2. kernel 3. Signals 4. programs vs. processes 5. permissions and access control 6. fork and exec 7. foreground and background processes

B.W.Gore Programming in the Linux Environment I Familiarity with the basic Linux command line environment

I Some experience in programming with the gcc and g++ compilers

I Insights into how the system behaves in various circumstances

Prerequisites

I Linux account

B.W.Gore Programming in the Linux Environment I Some experience in programming with the gcc and g++ compilers

I Insights into how the system behaves in various circumstances

Prerequisites

I Linux account

I Familiarity with the basic Linux command line environment

B.W.Gore Programming in the Linux Environment I Insights into how the system behaves in various circumstances

Prerequisites

I Linux account

I Familiarity with the basic Linux command line environment

I Some experience in programming with the gcc and g++ compilers

B.W.Gore Programming in the Linux Environment Prerequisites

I Linux account

I Familiarity with the basic Linux command line environment

I Some experience in programming with the gcc and g++ compilers

I Insights into how the system behaves in various circumstances

B.W.Gore Programming in the Linux Environment I in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were , Doug McIlroy, Joe Ossanna &

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX was developed in the late 1960s at AT&T Bell Laboratories

B.W.Gore Programming in the Linux Environment I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

B.W.Gore Programming in the Linux Environment I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

B.W.Gore Programming in the Linux Environment I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

B.W.Gore Programming in the Linux Environment I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

B.W.Gore Programming in the Linux Environment I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

B.W.Gore Programming in the Linux Environment I With rewrite in C, UNIX became portable to any hardware

UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

B.W.Gore Programming in the Linux Environment UNIX

I The UNIX operating system was developed in the late 1960s at AT&T Bell Laboratories

I Ken Thompson in 1969 made it work on DEC PDP-7

I Also involved, through ideas & contributions, were Rudd Canaday, Doug McIlroy, Joe Ossanna & Dennis Ritchie

I Ritchie ported UNIX to the more advanced PDP-11 in 1970

I He then developed C language & its compiler to work with UNIX

I In 1973, Thompson & Ritchie rewrote entire UNIX system code in C

I It broke the tradition of writing OS in assembly language

I With rewrite in C, UNIX became portable to any hardware

B.W.Gore Programming in the Linux Environment 2. multi-user 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing

B.W.Gore Programming in the Linux Environment 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user

B.W.Gore Programming in the Linux Environment 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user 3. having support for programming

B.W.Gore Programming in the Linux Environment 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors)

B.W.Gore Programming in the Linux Environment I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

B.W.Gore Programming in the Linux Environment I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

B.W.Gore Programming in the Linux Environment Unix ···

I It all resulted in UNIX becoming an operating system that was 1. time sharing 2. multi-user 3. having support for programming 4. unusually rich in features & productive (compared to its predecessors) 5. Hence, popular!

I Many free and commercial variants of UNIX are available today e.g.

I Solaris, HP-UX, AIX, Zenix, FreeBSD, Linux, ···

B.W.Gore Programming in the Linux Environment I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system

B.W.Gore Programming in the Linux Environment & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS

B.W.Gore Programming in the Linux Environment I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms

B.W.Gore Programming in the Linux Environment (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux

B.W.Gore Programming in the Linux Environment I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!)

B.W.Gore Programming in the Linux Environment I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds

B.W.Gore Programming in the Linux Environment I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ·········

Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities

B.W.Gore Programming in the Linux Environment Linux

I Unix-like computer operating system I In 1991, as a graduate student at the University of Helsinki, Linus Torvalds became curious about OS & got frustrated with limitations of existing Unix/Minix licensing terms I Developed his own variant called Linux (as his degree project!!!) I The core of Linux is the kernel, first released 5 October 1991 by Torvalds I Uses model of free and open source software development and distribution, prospered with GNU set of utilities I Today, Linux systems are everywhere, from embedded systems to supercomputers, from education to industry; in research labs, government establishments, financial institutions, ········· B.W.Gore Programming in the Linux Environment I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

B.W.Gore Programming in the Linux Environment I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8

B.W.Gore Programming in the Linux Environment I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

B.W.Gore Programming in the Linux Environment I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

B.W.Gore Programming in the Linux Environment I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

B.W.Gore Programming in the Linux Environment I None of these is useful independently

I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

B.W.Gore Programming in the Linux Environment I strength comes from their collaboration

Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

B.W.Gore Programming in the Linux Environment Linux internals

I Linux is made up of:

I The Linux kernel

I version ending in even number is stable e.g. 3.0.8 I version ending in odd number is unstable/testing/beta version e.g. 3.1.5

I The GNU tools like gcc, gawk, gnuplot etc.

I A graphical desktop environment (GNOME/KDE/xfce etc.)

I Application software: browsers, SciLab, eclipse etc.

I None of these is useful independently

I strength comes from their collaboration

B.W.Gore Programming in the Linux Environment shell

Diagrammatic Representation

Apllication S/W

A graphical desktop environment

GNU system tools/utilities

Linux Kernel

Computer H/W

B.W.Gore Programming in the Linux Environment Diagrammatic Representation

Apllication S/W

A graphical desktop environment shell

GNU system tools/utilities

Linux Kernel

Computer H/W

B.W.Gore Programming in the Linux Environment I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

B.W.Gore Programming in the Linux Environment I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

B.W.Gore Programming in the Linux Environment I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

B.W.Gore Programming in the Linux Environment I its controls are divided generally into:  Hardware management  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

B.W.Gore Programming in the Linux Environment  Hardware management  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:

B.W.Gore Programming in the Linux Environment  Memory management  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management

B.W.Gore Programming in the Linux Environment  File-system management  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management

B.W.Gore Programming in the Linux Environment  Software execution management

Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management  File-system management

B.W.Gore Programming in the Linux Environment Linux kernel

I core of the Linux system

I kernel controls all of the hardware and software on the computing system

I allocates resources as and when necessary

I executes commands/processes as and when necessary

I its controls are divided generally into:  Hardware management  Memory management  File-system management  Software execution management

B.W.Gore Programming in the Linux Environment I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

B.W.Gore Programming in the Linux Environment I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

B.W.Gore Programming in the Linux Environment I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

B.W.Gore Programming in the Linux Environment I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

B.W.Gore Programming in the Linux Environment I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

B.W.Gore Programming in the Linux Environment conditional statements , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with

B.W.Gore Programming in the Linux Environment , loops and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements

B.W.Gore Programming in the Linux Environment and functions!!!

The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops

B.W.Gore Programming in the Linux Environment The shell

I a basic way of communication between kernel & user

I it is a text-based command interpreter

I shell presents several user friendly facilities

I allows input/output redirection to files/console using pipes

I allows personalization of environment: user can create aliases for commands

I shell presents a powerful programming tool to work with commands: complete with conditional statements , loops and functions!!!

B.W.Gore Programming in the Linux Environment I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

B.W.Gore Programming in the Linux Environment I some examples:

I ls

I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

B.W.Gore Programming in the Linux Environment I ls

I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

B.W.Gore Programming in the Linux Environment I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

B.W.Gore Programming in the Linux Environment I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

B.W.Gore Programming in the Linux Environment I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

I whoami

B.W.Gore Programming in the Linux Environment I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

I whoami

I date

B.W.Gore Programming in the Linux Environment I whoami; date;

Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

B.W.Gore Programming in the Linux Environment Command

I a basic entity that can run a process

I shell does the job when command name is entered at command prompt (possibly with some arguments)

I some examples:

I ls

I ls -al

I whoami

I date

I possible to enter multiple commands on single line: a ; works as command terminator

I whoami; date;

B.W.Gore Programming in the Linux Environment I saves the effort of retyping that particular sequence of commands each time

I script is a program – a tool – which can easily be modified

I must be made executable – by chmod +x [script file name]

I making sure script can work across different flavours of Linux and/or different shells

Script

I script is nothing but a sequence of commands and control statements stored in a file

B.W.Gore Programming in the Linux Environment I script is a program – a tool – which can easily be modified

I must be made executable – by chmod +x [script file name]

I making sure script can work across different flavours of Linux and/or different shells

Script

I script is nothing but a sequence of commands and control statements stored in a file

I saves the effort of retyping that particular sequence of commands each time

B.W.Gore Programming in the Linux Environment I must be made executable – by chmod +x [script file name]

I making sure script can work across different flavours of Linux and/or different shells

Script

I script is nothing but a sequence of commands and control statements stored in a file

I saves the effort of retyping that particular sequence of commands each time

I script is a program – a tool – which can easily be modified

B.W.Gore Programming in the Linux Environment I making sure script can work across different flavours of Linux and/or different shells

Script

I script is nothing but a sequence of commands and control statements stored in a file

I saves the effort of retyping that particular sequence of commands each time

I script is a program – a tool – which can easily be modified

I must be made executable – by chmod +x [script file name]

B.W.Gore Programming in the Linux Environment Script

I script is nothing but a sequence of commands and control statements stored in a file

I saves the effort of retyping that particular sequence of commands each time

I script is a program – a tool – which can easily be modified

I must be made executable – by chmod +x [script file name]

I making sure script can work across different flavours of Linux and/or different shells

B.W.Gore Programming in the Linux Environment 1. the Bourne shell: includes sh, ksh, bash 2. the C shell: includes csh, tcsh

I the Bourne type shells usually have $ as the prompt character

I the C type shells usually have # as the prompt character

I sh is s POSIX standard shell

Types of shell

I Two major types:

B.W.Gore Programming in the Linux Environment 2. the C shell: includes csh, tcsh

I the Bourne type shells usually have $ as the prompt character

I the C type shells usually have # as the prompt character

I sh is s POSIX standard shell

Types of shell

I Two major types: 1. the Bourne shell: includes sh, ksh, bash

B.W.Gore Programming in the Linux Environment I the Bourne type shells usually have $ as the prompt character

I the C type shells usually have # as the prompt character

I sh is s POSIX standard shell

Types of shell

I Two major types: 1. the Bourne shell: includes sh, ksh, bash 2. the C shell: includes csh, tcsh

B.W.Gore Programming in the Linux Environment I the C type shells usually have # as the prompt character

I sh is s POSIX standard shell

Types of shell

I Two major types: 1. the Bourne shell: includes sh, ksh, bash 2. the C shell: includes csh, tcsh

I the Bourne type shells usually have $ as the prompt character

B.W.Gore Programming in the Linux Environment I sh is s POSIX standard shell

Types of shell

I Two major types: 1. the Bourne shell: includes sh, ksh, bash 2. the C shell: includes csh, tcsh

I the Bourne type shells usually have $ as the prompt character

I the C type shells usually have # as the prompt character

B.W.Gore Programming in the Linux Environment Types of shell

I Two major types: 1. the Bourne shell: includes sh, ksh, bash 2. the C shell: includes csh, tcsh

I the Bourne type shells usually have $ as the prompt character

I the C type shells usually have # as the prompt character

I sh is s POSIX standard shell

B.W.Gore Programming in the Linux Environment I shell undergoes an initialization phase

I usually a two step process, involves reading the files  /etc/profile  .profile I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

B.W.Gore Programming in the Linux Environment I usually a two step process, involves reading the files  /etc/profile  .profile I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

B.W.Gore Programming in the Linux Environment  /etc/profile  .profile I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

I usually a two step process, involves reading the files

B.W.Gore Programming in the Linux Environment  .profile I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

I usually a two step process, involves reading the files  /etc/profile

B.W.Gore Programming in the Linux Environment I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

I usually a two step process, involves reading the files  /etc/profile  .profile

B.W.Gore Programming in the Linux Environment I after reading both the files, the prompt character is presented

Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

I usually a two step process, involves reading the files  /etc/profile  .profile I If any file doesn’t exist, it is skipped and no error is shown

B.W.Gore Programming in the Linux Environment Shell Initialization

I When login program start shell, the parameters required for operation of shell to start are missing

I shell undergoes an initialization phase

I usually a two step process, involves reading the files  /etc/profile  .profile I If any file doesn’t exist, it is skipped and no error is shown

I after reading both the files, the prompt character is presented

B.W.Gore Programming in the Linux Environment I by this, shell is put in interactive mode i.e. ready to interact with user

I there is non-interactive mode of shell execution, where shell terminates after executing some commands e.g. when you logout

I shell can be started non-interactively by issuing command /bin/sh [script filename]

How login starts the shell

I login automatically starts the program: /bin/sh

B.W.Gore Programming in the Linux Environment I there is non-interactive mode of shell execution, where shell terminates after executing some commands e.g. when you logout

I shell can be started non-interactively by issuing command /bin/sh [script filename]

How login starts the shell

I login automatically starts the program: /bin/sh

I by this, shell is put in interactive mode i.e. ready to interact with user

B.W.Gore Programming in the Linux Environment I shell can be started non-interactively by issuing command /bin/sh [script filename]

How login starts the shell

I login automatically starts the program: /bin/sh

I by this, shell is put in interactive mode i.e. ready to interact with user

I there is non-interactive mode of shell execution, where shell terminates after executing some commands e.g. when you logout

B.W.Gore Programming in the Linux Environment How login starts the shell

I login automatically starts the program: /bin/sh

I by this, shell is put in interactive mode i.e. ready to interact with user

I there is non-interactive mode of shell execution, where shell terminates after executing some commands e.g. when you logout

I shell can be started non-interactively by issuing command /bin/sh [script filename]

B.W.Gore Programming in the Linux Environment Commands for file-system handling

I mkdir

I cd

I pwd

I cp, mv, rm

I cat

I ls

I Editors: vi, gedit, nedit, emacs, ···

I chown, chgrp, chmod

I symbolic links: ln

I pipes: |, >, <>>, <<

B.W.Gore Programming in the Linux Environment I listing running processes

I killing a process

I parent-child processes

I background/foreground precesses and their switching

Next lecture

I Processes

I starting a process

B.W.Gore Programming in the Linux Environment I killing a process

I parent-child processes

I background/foreground precesses and their switching

Next lecture

I Processes

I starting a process

I listing running processes

B.W.Gore Programming in the Linux Environment I parent-child processes

I background/foreground precesses and their switching

Next lecture

I Processes

I starting a process

I listing running processes

I killing a process

B.W.Gore Programming in the Linux Environment Next lecture

I Processes

I starting a process

I listing running processes

I killing a process

I parent-child processes

I background/foreground precesses and their switching

B.W.Gore Programming in the Linux Environment References

I Ritchie, D.; Thompson, K.; “The UNIX Time-Sharing System”, Communications of ACM 17(1974), p. 365. I Kernighan, B.W.; Pike, R.; “The unix Programming Environment”, Prentice-Hall, 1984. I Bach, M.J.; “The Design of The UNIX Operating System”, Prentice-Hall, 1986. I http://tldp.org/ I https://www.kernel.org/ I http://www.linuxfoundation.org/ I CMS library books: CMS-78, CMS-877, CMS-1287, CMS-1626 I Robbins a.; Beebe, N.H.F.; “Classic Shell Scripting - Hidden Commands that Unlock the Power of Unix”, O’Reilly Media, 2005.

B.W.Gore Programming in the Linux Environment