Sunteți pe pagina 1din 31

Introduction to UNIX System

Objectives

Introduction to Features of UNIX OS.

Input and Output in UNIX.

Programs and Processes in UNIX.

Permissions and IDs in UNIX.

UNIX Systems Programming Satyam Computer Services Ltd 1


Introduction to UNIX System

Objectives

Error Handling in UNIX.

Introduction to Signals in UNIX.

Introduction to System Calls in UNIX.

UNIX Systems Programming Satyam Computer Services Ltd 2


Introduction to UNIX System

Introduction
Bell Labs, GE and Project MAC of MIT ( 1965 )
Developed a new OS called Multics
Provide simultaneous access to users
UNIX system was first described in 1974
By ken Thompson and Dennis Ritchie
Thompson and Ritchie implemented the UNIX
On PDP-7 computer and later on PDP-11 ( 1971 )
In 1973 the UNIX was written in
C programming language

UNIX Systems Programming Satyam Computer Services Ltd 3


Introduction to UNIX System

Features of UNIX OS

Simple user interface.

Hierarchical file system.

Consistent format for files

byte stream.

UNIX Systems Programming Satyam Computer Services Ltd 4


Introduction to UNIX System

Features of UNIX OS

Simple, Consistent interface to devices.

Multi -xxx system.

Protection of file data.

Peripheral devices treated as files.

UNIX Systems Programming Satyam Computer Services Ltd 5


Introduction to UNIX System

bin usr
etc
unix

sh date who src bin


passwd
cmd

date.c who.c

Sample File system Tree


UNIX Systems Programming Satyam Computer Services Ltd 6
Introduction to UNIX System

Other applications

sh who
cpp Kernel date

cc comp Hardware wc

as a.out
ld vi

Architecture of UNIX System


UNIX Systems Programming Satyam Computer Services Ltd 7
Introduction to UNIX System

Input and Output


Uses file descriptors.

Small non-negative integers .

All shells open three descriptors


standard input

standard output

standard error

UNIX Systems Programming Satyam Computer Services Ltd 8


Introduction to UNIX System

Programs
Collection of instructions and data in a file.
Marked executable.

File contents are arranged according

To the rules established by kernel.

This object file resides on the hard disk.

Read into memory and executed by kernel.

UNIX Systems Programming Satyam Computer Services Ltd 9


Introduction to UNIX System

Processes .
An executing instance of a program.

Kernel creates a new process

environment in which program executes.

Creation of new process is done

By issuing a system call.

UNIX Systems Programming Satyam Computer Services Ltd 10


Introduction to UNIX System

Processes.
The program is used to initialize

Instructions

User data

Several concurrently running process can be initialized

from the same program

UNIX Systems Programming Satyam Computer Services Ltd 11


Introduction to UNIX System

Processes.
Process system data includes attributes
Current directory.

Open files.

Descriptors.

Accumulated CPU time

A process cannot access/ modify


The system data directly.

UNIX Systems Programming Satyam Computer Services Ltd 12


Introduction to UNIX System

Process ID and Process Groups

Every process has a process ID.

Guaranteed to have unique positive integer.

All processes have a parent

Exception swapper, init and pagedaemon process

UNIX Systems Programming Satyam Computer Services Ltd 13


Introduction to UNIX System

Process ID and Process Groups

Related processes can be organized into

process groups

One group member is the group leader.

Each member has the process-group-ID.

UNIX Systems Programming Satyam Computer Services Ltd 14


Introduction to UNIX System

Process ID and Process Groups

A process group can have a control terminal

When group leader terminates :-

All process with the same control terminal are sent hangup signal.

UNIX Systems Programming Satyam Computer Services Ltd 15


Introduction to UNIX System

Process ID and Process Groups

Process ID Uniquely identifies a process.

Parent-process ID Process -ID of the processs parent

Process group ID Process ID of the group leader

UNIX Systems Programming Satyam Computer Services Ltd 16


Introduction to UNIX System

Permissions in UNIX.
User ID ,Group ID

positive integers associated with users login name .

Called

Real user ID.

Real group ID.

UNIX Systems Programming Satyam Computer Services Ltd 17


Introduction to UNIX System

Permissions in UNIX.
Two IDs associated with a process

effective user ID.

effective group ID.

UNIX Systems Programming Satyam Computer Services Ltd 18


Introduction to UNIX System

Error Handling in UNIX.

Most Unix system calls return

Negative value on error.

The global variable errno

Is set to a value for more information.

UNIX Systems Programming Satyam Computer Services Ltd 19


Introduction to UNIX System

Error Handling in UNIX.

The file < errno.h > defines the variable errno.

The value of errno is not cleared

if an error does not occur

The value of error is never set to 0 (zero).

UNIX Systems Programming Satyam Computer Services Ltd 20


Introduction to UNIX System

Error Handling in UNIX.


Two functions to print error message

strerror( ).

perror( ).

UNIX Systems Programming Satyam Computer Services Ltd 21


Introduction to UNIX System

Error Handling in UNIX.

char *strerror( int errnum );

Maps errno into an error message string.


Returns a pointer to a string.

UNIX Systems Programming Satyam Computer Services Ltd 22


Introduction to UNIX System

Error Handling in UNIX.

void perror( const char *msg );

Outputs the string pointed to by msg,


Followed by a colon and a space,
Then the error message.

UNIX Systems Programming Satyam Computer Services Ltd 23


User Programs Libraries
User Level
Kernel Level
System call interface

File subsystem

Process
Buffer cache
control
Character block subsystem
Device drivers

Hardware control
Hardware Level

Block diagram of the system Kernel


UNIX Systems Programming Satyam Computer Services Ltd 24
Introduction to UNIX System

System Calls in UNIX


Called service points for kernel service
The system calls are one feature of UNIX
That cannot change

Unix version 7 50 system calls.


4.4 BSD 110system calls.
SVR4 120 system calls.

UNIX Systems Programming Satyam Computer Services Ltd 25


Introduction to UNIX System

System Calls in UNIX

application
User process
malloc

sbrk Kernel

malloc and sbrk system call.

UNIX Systems Programming Satyam Computer Services Ltd 26


Introduction to UNIX System

Programmers reference manuals


Section 1 Commands, Precompiled utilities.

Section 2 System Calls, For Unix Services.

Section 3 C Library Facilities.

Section 4 Header Files.

Other Sections Miscellaneous topics.

UNIX Systems Programming Satyam Computer Services Ltd 27


Introduction to UNIX System

Header files

dirent . h Directory entries

errno . h Error codes

fcntl . h File control

signal . h Signals

UNIX Systems Programming Satyam Computer Services Ltd 28


Introduction to UNIX System

Header files

stddef . h Standard definitions

stdio . h Standard I/O

string .h string operations

time . h time and date

UNIX Systems Programming Satyam Computer Services Ltd 29


Introduction to UNIX System

Header files

Headers for IPC

sys/ipc . h IPC

sys/msg . h Message Queues

sys/sem . h Semaphores

sys/shm . h Shared memory

UNIX Systems Programming Satyam Computer Services Ltd 30


Introduction to UNIX System

Header files

sys/stat . h file status

sys/times . h Process times

sys/types.h Primitive system data types

sys/wait . h Process Control

UNIX Systems Programming Satyam Computer Services Ltd 31

S-ar putea să vă placă și