You are on page 1of 40

The UNIX Operating

System
MODULE 1
Course In Charge:
Ms.UMA.N
Section A & C 3rd
semester
Coursecode:20CSE35
MODULE 1
Getting started & Understanding UNIX commands: Operating System,
UNIX Operating System, UNIX architecture, features of UNIX,The
POSIX Standards.UNIX and POSIX APIs: The POSIX APIs, The UNIX and
POSIX Development Environment, API Common Characteristics.
OPERATING SYSTEM

QUESTIONS?

WHAT?

WHY?

TYPES?

HOW IT WORKS?
Operating Systems

Image By Golftheman - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=4558519

 Operating systems allow the separation of hardware management from


applications/programs.
 This allows the applications to work across different hardware platforms,
although the applications are still specific to the OS.
what is an OS

Life giver to a computer-provides with basic intelligence for

computer to work with.

A program which resides in the main memory all the time from

the time,the system is booted.

Interface between Application Programs and Computer Hardware

Controls functionalities like opening and closing of
files,accessing the printer,writing to memory etc.

Resource Manager

Without an operating system,any powerful system will be

useless
SERVICES OFFERED

Scheduling Decision about which program to run,and for how long in a
multiprogrammed environment .

Memory management accross various applications.

Device management ie Access control to various hardware devices like
hard disks,terminals,printers,modems etc.

Error management ie Reporting errors to application programs

Providing basic user tools like creating
directories,creating ,deleting,copying files,sending mails,performing
backups etc.

Resource management.

Security
TYPES

Multiuser – Two or more users work with the computer at the same time

Multitasking – Two or more processes running at the same time.

Multithreading – Two or more parts of the same process running at the
same time.

Distributed Opertaing Sytem-Manages group of distinct computers and
makes them appear to be a single computer

Embedded-Designed to be used in Embedded Systems
UNIX OS

Unix(Uniplexed Information and computing services) is developed
in Bell Labs in 1970 by Ken thompson with Dennis Ritchie.

UNIX has introduced many concepts which were previously unknown to

computing community like many complicated tasks can be done in few
keystrokes.

In UNIX,we can combine many simple commands to do a complex task.

Unix Variants:Solaris Unix,AIX,HP Unix,BSD,All Linux versions
UNIX ARCHITECTURE

The UNIX architecture comprises of two major components-

The shell and the Kernel.

The divison of labour approach between the kernel and the shell is
one of the most powerful feature of the UNIX architecture.The Shell
interacts with the user and the kernel with the machine hardware.
UNIX ARCHITECTURE
THE KERNEL

The kernel is the core part of the operating system.

It is a programs Gateway to computers resources

It is loaded into memory from the time system is booted.

It manages the systems resources

Allocates time between the users and the processes

Decides process priorities

Executes tasks for the smooth functioning of the system.

The user programs which require hardware services,use the,services of
the kernel and get the job done via a set of system calls.
THE SHELL

It is also known as the command Interpreter.

The shell takes command from the user,deciphers the special
characters that it finds and rebuilds a complete command line.

It also communicates with the kernel to see that command is
executed.

It acts as an interface between the user and the kernel.

The shell is also a programming language.

Represented by /bin/sh

There can be many shells running in action for each user logged in

Bourne shell (sh),Bourne Again Shell(Bash),C shell,K Shell etc
THE FILES AND PROCESSES


File is an array of bytes that store the information.

Files are organized in hierarchical structure.

A program in execution is a process ie.time image of a Program.

Process is also organized in heirarchical structure.
THE SYSTEM CALLS


System calls are used to communicate with the kernel.

All the UNIX flavours use one thing in common -they all use the same
system calls.

System calls are described in POSIX specification.

Eg:To perform the actual write operation it uses write() system
call,open() system call can be used to open a file or a device etc.
UNIX operating system
 First developed in 1970s, it is a multitasking OS that
supports simultaneous use by multiple users.
 Strengths
 Command-line based.
 Supports thousands of small programs running simultaneously.
 Easy to create pipelines from individual programs.
 Multi-user support and partitioning is baked in.
 Challenges
 Command-line based.
 Finding help and documentation can be onerous.
 Many different variants.
UNIX operating system-Features

 Multiuser Support
 Multitasking
 Building Block Approach/Do one thing well approach
 Featureless file
 Unix tool kit
 Pattern Matching
 Programming Facility
 Portability and System Calls
 Documentation
SYSTEM ADMINISTRATION
TASKS
 Allocate user accounts
 Maintain File System
 Take Backups
 Addition,Deletion of Users
 Overall System Maintanance
COMMANDS

 To Create an account-Superuser Privileges-root


 To add user account-adduser
 To delete a user-userdel
 To login to account-login
 To logout-logout or ctrl+d
 To change the password-passwd
 To know the users logged in the system-who,users,w
 To know ones login among multiple users-whoami
 To know the terminal Name-tty
 To know your SHELL -query on $SHELL
 To know the path of files traveresed-$PATH
OBSERVATIONS ABOUT UNIX
COMMANDS
 Commands are case sensitive(PASSWD AND passwd
 are different)
 commands are very short
 Each command is designed to do a simple task
 Every command to execute one has to hit [Enter] Key
 Backspace-Ctrl+h
 Command Interruption-ctrl+c
 To logout:ctrl+d
 To kill a command line without execution:ctrl+u
 Alternative to [enter] key:ctrl+j,ctrl+m
General Features of a Unix Command

 Commands are case sensitive


 commands are very short(max 3 or 4)
 Each command is designed to do a simple task
 In unix ,commands are also files generally stored as files
POSIX standards(Portable OS
Interface
 Standards defined by IEEE computer society to
maintain portability between different UNIX OS’s.
 Subgroups of POSIX

POSIX.1 committe-base OS,manipulation of
files and processes

POSIX 1.b(1003.4-1994)-RTOS interfaces

POSIX 1.c-Multithreaded Programming
Interface
 To Ensure POSIX compliance- prefix-
_POSIX_SOURCE in every Source module
POSIX standards(Portable OS
Interface
 _POSIX_C_SOURCE – A constant with Time stamp
Value which checks the conformance of user
programs to that standard.
_POSIX _C _SOURCE MEANING
VALUE(YYYYMMLong

Integer)

198808L FIRST VERSION OF POSIX.1
COMPLIANCE
199009L SECOND VERSION OF POSIX.1
COMPLIANCE
199309L POSIX.1 AND POSIX.1b
COMPLIANCE
POSIX_VERSION

_ POSIX _ VERSION -CONSTANT DEFINED IN


unistd.h conforms to the POSIX VERSION to which the
system conforms.
POSIX FEATURE TEST MACROS
FEATURE TEST MACRO EFFECTS IF DEFINED

_POSIX_JOB_CONTROL The system supports job control

_POSIX_SAVED_ID keeps saved set-UID and set-GID

_POSIX_CHOWN_RESTRICTED If return value==-1,then


user may change ownership of files owned by them
else only users with special privilege can do so

_POSIX_NO_TRUNC If the defined value is -1, any long pathname


passed to an API is silently
truncated to NAME_MAX bytes, otherwise error is
generated.
_POSIX_VDISABLE If defined value is -1, there is no disabling
character for special characters for all terminal
device files. Otherwise the value is the disabling
character value.
LIMIT CHECKING-limits.h
Compile time limit Min Meaning
Value
_POSIX_CHILD_MAX 6 Maximum number of child
processes that may be created
at any one time by a process.
_POSIX_OPEN_MAX 16 Maximum number of files that a
process can open
simultaneously.
_POSIX_STREAM_MAX 8 Maximum number of I/O streams
opened by a process
simultaneously.
_POSIX_ARG_MAX 4096 Maximum size, in bytes of
arguments that may be passed to
an exec function.
_POSIX_NGROUP_MAX 0 Maximum number of supplemental
groups to which a
process may belong
LIMIT CHECKING
Compile time Min Meaning
limit Value
_POSIX_PATH_MAX 255 Maximum number of characters
allowed in a path name

_POSIX_NAME_MAX 14 Maximum number of characters


allowed in a file name
_POSIX_LINK_MAX 8 Maximum number of links a file
may have
_POSIX_PIPE_BUF 512 Maximum size of a block of data
that may be atomically read
from or written to a pipe
_POSIX_MAX_INPUT 255 Maximum capacity of a
terminal’s input queue (bytes)
LIMIT CHECKING
Compile time limit Min Meaning
Value
_POSIX_MAX_CANON 255 Maximum size of a terminal’s
canonical input queue

_POSIX_SSIZE_MAX 32767 Maximum value that can be


stored in a ssize_t-typed
object
_POSIX_TZNAME_MAX 3 Maximum number of characters
in a time zone name
LIMIT CHECKING(POSIX 1.b)
Compile time Min Meaning
limit Value
_POSIX_AIO_MAX 1 Number of simultaneous asynchronous
I/O.

_POSIX_AIO_LISTIO_ 2 Maximum number of operations in one


MAX listio.

_POSIX_TIMER_MAX 32 Maximum numberof timers that can be


used simultaneously by a process

_POSIX_DELAYTIMER 32 Maximum number of overruns allowed


_MAX per timer

_POSIX_MQ_OPEN_M 2 Maximum number of message queues


AX that may be accessed simultaneously per
process
LIMIT CHECKING(POSIX 1.b)
Compile time Min Meaning
limit Value
_POSIX_MQ_OPEN_M 2 Maximum number of message
AX queues that may be accessed
simultaneously per process
_POSIX_MQ_PRIO_M 2 Maximum number of message
AX priorities that can be assigned to the
messages
_POSIX_RTSIG_MAX 8 Maximum number of real time
signals
_POSIX_SIGQUEUE_ 32 Maximum number of real time
MAX signals that a process may
queue at any time.
_POSIX_SEM_NSEMS 256 Maximum number of semaphores
_MAX that may be used simultaneously per
process.
_POSIX_SEM_VALUE_ 32767 Maximum value that may
MAX assigned to a semaphore.
FUNCTIONS WHICH CAN QUERY
THE LIMIT VALUES AT RUN TIME

 Long sysconf(const int


limit_name);//System wide general
 Long pathconf(const char*
pathname,int flimit_name);
 Long fpathconf(const int fdesc,int
flimitname); //file related
Limit name argument constants

Limit Sysconf return data value

_SC_ARG_MAX Maximum size of argument values


(in bytes) that may be passed to
an exec API call

_SC_CHILD_MAX Maximum number of child


processes that may be owned by a
process simultaneously
_SC_OPEN_MAX Maximum number of opened files
per process
_SC_NGROUPS_MAX Maximum number of supplemental
groups per process
_SC_CLK_TCK The number of clock ticks per
second
Limit name argument constants

Limit Sysconf return data value

_SC_JOB_CONTROL The _POSIX_JOB_CONTROL value

_SC_SAVED_IDS The _POSIX_SAVED_IDS value

_SC_VERSION The _POSIX_VERSION value

_SC_TIMERS The _POSIX_TIMERS value

_SC_DELAYTIMERS_MA Maximum number of overruns


X allowed per timer

_SC_RTSIG_MAX Maximum number of real time


signals.
Limit name argument constants

Limit Sysconf return data value


_SC_MQ_OPEN_MAX Maximum number of messages
queues per process.
_SC_MQ_PRIO_MAX Maximum priority value
assignable to a message
_SC_SEM_MSEMS_MAX Maximum number of semaphores per
process
_SC_SEM_VALUE_MAX Maximum value assignable to a
semaphore.
_SC_SIGQUEUE_MAX Maximum number of real time
signals that a process may queue
at any one time
Limit name argument constants

Limit Sysconf return data value

_SC_AIO_LISTIO_MAX Maximum number of operations in


one listio.

_SC_AIO_MAX Number of simultaneous


asynchronous I/O
Limit name argument constants

Limit pathconf return data value

_PC_CHOWN_RESTRI The _POSIX_CHOWN_RESTRICTED


CTED value
_PC_NO_TRUNC Returns the _POSIX_NO_TRUNC
value
_PC_VDISABLE Returns
value the _POSIX_VDISABLE
_PC_PATH_MAX Maximum length of a pathname (in
bytes)
_PC_NAME_MAX Maximum length of a filename (in
bytes)

_PC_LINK_MAX Maximum number of links a file


may have
Limit name argument constants

Limit pathconf return data value

_PC_PIPE_BUF Maximum size of a block of data


that may be read from or written
to a pipe
_PC_MAX_CANON maximum size of a terminal’s
canonical input queue
_PC_MAX_INPUT Maximum capacity of a terminal’s
input queue
UNIX AND POSIX APIs

 Determine the system


configuration and user
information.
 Files manipulation.
 Processes creation and control.
 Inter-process communication.
 Signals and daemons
 Network communication.
API common characteristics

 Many APIs returns an integer value


which indicates the termination status
 API return -1 to indicate the execution
has failed, and the global variable errno
is set with an error code.
 A user process may call perror function
or serror function defined in errno.h
Error Codes

ERROR STATUS CODE MEANING

EACCESS No Access Permission to Perform an


operation via API
EPERM No superuser privilege for calling process

ENOENT Invalid filename specified to API

BADF Invalid file descriptor to API

EINTR API execution aborted due to signal


interruption
Error Codes

ERROR STATUS CODE MEANING

ENOEXEC API should not execute a program via exec


API
ECHILD A Process doesnt not have any child
process to wait on.

You might also like