Vous êtes sur la page 1sur 7

Experiment 4 Introduction to UNIX Operating System and Basics of File Management and Interposes Communication Introduction to UNIX

UNIX is an operating system. The job of an operating system is to organize various parts of the computer like the processor. The on-board memory, the disk drivers, keyboards, video monitors, etc. and to perform useful tasks. The operating system is the master controller of the computer the glue that holds together all the components of the system. Including the administrators, programmers and users. When we want the computer to do something like start a program. copy a file .or display the contents of a directory, it is the operating system that must perform those tasks. More than anything else, the operating system gives the computer its recognizable characteristics. It would be difficult to distinguish between two completely different computers, if they were running the same operating system. Conversely, two identical computers. running different operating systems, would appear completely different to the user UNIX was created in the late 1960s, in an effort to provide a multiuser, multitasking system for use by programmers. The philosophy behind the design of UNIX was to provide simple, yet powerful utilities that could be pieced together in a flexible manner to perform a wide variety of tasks. The kernel is the core of the UNIX operating system. Basically, the kernel is a large program that is loaded into memory when the machine is turned on , and it controls the allocation of hardware resources from that point forward. The kernel knows what hardware resources are available (like the processor(s), the on-board memory, the disk driver, Network interfaces, etc.). and it has the necessary programs to all the devices connected to it. Any program that is submitted by the user and being executed by the UNIX kernel is called process. The UNIX kernel can keep track of many processes at once, dividing its time between the jobs submitted to it. Each process submitted to the kernel is given a unique process ID . singletasking operating systems, like DOS, or the Macintosh system., can only perform one job at a time . a user of a single-tasking system can switch to different windows, running different applications. But only the application that is currently being used is active. Any other task that has been started is suspended until the user switches back to it. A suspended. When a suspended job is reactivated. It begins right where it left off. As if nothing had happened. Actually. It only appears that UNIX is performing the jobs simultaneously, In reality. It is running only one job at a time, but quickly switching between all of its ongoing tasks. The UNIX kernel will execute some instructions from job A. and then set job A aside. And execute instructions from job B. The concept of switching between queued jobs is called process scheduling.

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

The UNIX Shell

Experiment 4 Introduction to UNIX Operating System and Basics of File Management and Interposes Communication

The shell is perhaps the most important program on the UNIX system, from the end-users standpoint. The shell is the interface with the UNIX system, the middleman between the user and kernel. The shell is the type of program called an interpreter. An interpreter operates in a simple loop: it accepts a command, interprets the command, executes the command, and then wais for another command. The shell displays a prompt to notify the user that it is ready to accept the command.

>

Read Command

Display Prompt

Interpret command

Execute Command< The shell recognizes a limited set of commands. And one must give command to the shell in a way that it understands. Each shell command consists of a command name, followed by command options (if any are desired) and command arguments (if any are desired). The command name, options and arguments are separated by blank space. The UNIX files system structure All the stored information on a UNIX computer is kept in a file system. The UNIX file System is hierarchical (resembling a tree structure).The tree is anchored at a place called the root designated by a slash /. Every item in the UNIX file system tree is either a file, or a directory. A directory is like a file folder .A directory can contain files, and other directory .A directory contained within another is called the child of the other. A directory in the file system tree may have many children, but it can only have one parent. A file can hold information, but cannot contain other files or directories.

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Experiment 4 Introduction to UNIX Operating System and Basics of File / Management and Interposes Communication

bin

usr

etc

users

lib

admin

staff

student

harsh

maulik

Part of the file system tree Every item in a UNIX file system can be defined as belonging to one of four possible Types: Ordinary files Ordinary files can contain text, data, or program information ,An ordinary file Cannot contain another file, or directory . An ordinary file can be thought of as a One-dimension array of bytes. Directories Directories are containers that can hold files, and other directories. A directory is actually implemented as a file that has one line for each item contained within the Directory. Each line in a directory file contains only the name of the item and a numerical reference to the location of the item. The reference is called an i-node, and is an idex to a table known as the i-list. The i-list is a complete list of all the storage space available to the file system. Special files Special files represent input/output (i/o) devices like a try (terminal), a disk drive, Or a printer. Because UNIX treats such devices as files, a degree of compatibility can be achieved between device i/o and ordinary file i/o allowing for the more efficient use of software.

Links

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Experiment 4 Introduction to UNIX Operating System than Basics of File A links is a pointer to another file. A directory is nothing more and a list of the Names and i-nodes of files. A Management and hard link, in which the i-node points directly to directory entry can be Interposes Communication
another file. A hard link to a file is indistinguishable from the file itself. When a hard link is made then the i-node of two different Directory file entries point to the same mode for that reason, hard links cannot span cross file system. A soft link (or symbolic link) provides an indirect pointer to a file a soft links are distinguishable from files, and can span across file systems. Standard input and output and redirecting them Every program you run from the shell opens three files: standard input, standard output, and standard error. The files provide the primary means of communications between the programs, and exist for as the process runs. The standard output provides a way to send data to a process. As a default, the standard input is read from the terminal keyboard. The standard output provides a means for the program to output data. As a default, the standard output goes to the terminal display screen. The standard error is where the program reports any errors encountered during execution. By default, the standard error goes to the terminal display. Directing standard input/standard output/standard error to keyboard/display is handled by a data structure called user file descriptor table (UFDT). This is a data structure created by the kernel for each process it is executing and these points to various files used by the process. As all devices are also looked upon as files by UNIX kernel, keyboard as well as display device are also treated as files. UFDT for every open process has three default entries, namely 0 (for input from keyboard), 1 ( for out to display) and 2 (for error to display ) thus any input operation (e.g. Scanf in c program, Cin in C++ program), output or error message (e.g. printf in C program , Cout and cerr in C++ program ) will by default be directed to the standard input and output files. However, shell supports various operators using which it is possible to redirect this default allocation. Operators used for these are < > >> 2> input redirection Output redirection Output redirection (append mode) error redirection

Using the less-than sign with a file name as < file1

In a shell commend instructs the shell to read input from a file called file 1 instead of from the keyboard. i.e. in UFDT at 0 keyboard is replace by file1

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Experiment 4 Introduction a UNIX as Using the greater-than sign with tofile nameOperating System and Basics of File > file2 Management and Interposes Communication
Causes the shell to place the output from the command in a file called file2 instead of on the screen, i.e. in UFDT at 1 screen is replace by file2. If the file file2 already exists, the old version will be overwritten. Use two greater-than signs to append to an existing file. For example: file1>>file2 causes the shell to append the output from a command to the end of a file called file2. If the file file2 does not already exist, it will be created. Using the 2> sign with a file name as > file3 Interprocess communication using the shell pipe operator UNIX allows you to connect processes by letting the standard output of one process feed into the standard input of another process. That mechanism is called a pipe. Connecting Simple processes in a pipeline allows you to perform complex tasks without writing Complex programs. Pipe is a binary operator with the following syntax: $p1 / p2 Where p1 and p2 are two executable programs (or unix commands). The semantics of the pipe operator is that the commands p1 and p2 are connected in the sanse that the output of process p1 becomes the input of process p2.Recall that a program under execution is a process. _____________________________________________________________________________ Example 1 A C program named as gen.c to generate 0 to 99. #include<stdio.h> int main() { int i; for(i=1;i<100;i++) printf(%d \n,i); }

Example 2 A C program to sum all the integers feed in. To end summation any special character can be given !

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Experiment 4 #include<stdio.h> Introduction to UNIX Operating System and Basics of File int main() Management and Interposes Communication
{ int i; int sum=0; while(scanf(%d,&i) { sum = sum + i; } printf(\n %d \n, sum); } To generate executable of gen.c and sum.c Sgec gen.c -ogen.out Sgen sum.c -osum.out To execute S./gen.out This will list 1 to 99 on the screen. S./gen.out > gen.text This will not give the output on screen , but create a file gen.text and write 1 to 99 in the file. S./gen.out >> gen.text This is append 1 to 99 to the previous data present in gen.text S./sum.out This will ask for number through the keyboard and after entering the number followed by the special character it will display the sum of these numbers on the screen. S./sum.out < ge.text This will read the number from the file gen.text instead from keyboard and would print the sum on the screen. (Any special character is required to be added in gen.text at the end.)

S./gen.out ./sum.out To executables being connected to file operator, the output of gen.out would become the input of sum.out gen.out would be executed but numbers would not be shown on the screen but passed to sum.out and the sum would get directly printed on the screen.

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Experiment 4 Introduction to UNIX Operating System and Basics of File Management and Interposes Communication

TH

SEM

EC

EMBEDDED SYSTEM

CY/C5

ROLL NO.- 47

ATMIYA INSTITUTE OF TECHNOLOGY & SCIENCE, RAJKOT.

Vous aimerez peut-être aussi