Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2: Linux & POSIX “She sells bash shells by the C shore”

Similar presentations


Presentation on theme: "Chapter 2: Linux & POSIX “She sells bash shells by the C shore”"— Presentation transcript:

1 Chapter 2: Linux & POSIX “She sells bash shells by the C shore”

2 The Linux kernel We know that the linux kernel manages system resources and especially when applications are running “on” the computer The kernel itself cannot communicate, even though it handles user interface devices: “ You can compute all you like, but if you can’t I/O, it don’t mean a thing.” Enter the shell: A shell is a program (interpreter) that 1.prints a prompt, 2.reads a line of input from you (the “command”) 3.interprets it to manipulate files or run other programs

3 The shell: more… Early PCs (without “windows”) had a DOS prompt. Aside, what does DOS acronym mean? That DOS prompt was printed by the DOS shell, called: command.com The linux kernel has multiple shells that can be used by different users at the same time. There are 3 major types. 1.The Bourne-compatible shells use the syntax derived from the original Bourne shell.Bourne shell 2.C shells use the syntax from the original C shell.C shell 3.Nontraditional shells that invent their own syntax, or borrow one from some programming language Examples Bash shell http://www.gnu.org/software/bash/http://www.gnu.org/software/bash/ Bourne shell Bourne again shell Korn shell

4 built-ins A shell can execute a built-in command itself, without interpretation. Compilers have built-in commands, called APIs or functions, also. (Most math functions are built in, a possible reason why java math API’s do not need to be associated with “an object” Characteristics: Faster and more efficient Can change the state of the shell itself Which commands are built-in? It depends on the shell It also depends on POSIX compliance.

5 built-ins: more… There are three levels of built-in utilities: Utility built-ins are part of the shell as programming language, and control execution.., :, break, continue, return, trap, exit, exec Special built-ins need to be implemented inside the shell They act on the shell's internal settings: cd, dir, pushd, popd ; job control utilities: bg, disown, fg, jobs, wait; utilities that read/manipulate attributes: builtin, command, hash, read, type, ulimit utilities related to interactive features: fc, history, bind. Performance built-ins: utilities implemented for speed: echo, printf, test, true, false.

6 What’s POSIX? Short Answer: Portable Operating Systems Interface for uniX

7 What’s POSIX? A longer answer… All unix systems have their own cute little quirks (aix, solaris, linux, etc.) POSIX defines a standard to work with, across all the “nix’s” + any other OS that wants to be POSIX compliant (mainframe OS’s, windows) Standards? The Open Group, and IEEE set standards for (multiple) POSIX versions. pubs.opengroup.org/onlinepubs/9699919799/ Open Group Base Specifications Issue 7 == IEEE Std 1003.1 ™, 2013 Edition The standards evolve as technologies (HW/SW) change.

8 What’s POSIX? A longerer answer… POSIX 7 defines the following: ANSI C extensions that appear outside the bounds of C (file I/O, networking) Utilities (builtins too): ls, cd, echo, mkdir, mkdir() grep sed Shell language: GNU bash Environment variables: PATH How programs exit on error condition (errno) Filesystem directory structure: /home, /usr, /etc Filesystem naming conventions More pubs.opengroup.org/onlinepubs/9699919799/nfindex.html

9 Let’s make a directory! pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html NAME mkdir - make directories SYNOPSIS mkdir [-p] [-m mode] dir... DESCRIPTION The mkdir utility shall create the directories specified by the operands, in the order specified. For each dir operand, the mkdir utility shall perform actions equivalent to the mkdir() function defined in the System Interfaces volume of POSIX.1-2008, called with the following arguments: mkdir() The dir operand is used as the path argument The value of the bitwise-inclusive OR of S_IRWXU, S_IRWXG, and S_IRWXO is used as the mode argument.

10 Let’s write code to make a directory! pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html NAME mkdir - make a directory relative to directory file descriptor SYNOPSIS #include sys/stat.h int mkdir(const char *path, mode_t mode); DESCRIPTION The mkdir() function shall create a new directory with name path. The file permission bits of the new directory shall be initialized from mode. These file permission bits of the mode argument shall be modified by the process' file creation mask.

11 A coding example #include // int status; //... status = mkdir("/home/cnd/mod1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); If (status == 0) { // } else //


Download ppt "Chapter 2: Linux & POSIX “She sells bash shells by the C shore”"

Similar presentations


Ads by Google