+ All Categories

Unit 1

Date post: 08-Sep-2014
Category:
Upload: siddr
View: 1,201 times
Download: 0 times
Share this document with a friend
Description:
 
Popular Tags:
16
UNIT -1 INTRODUCTION Prepared By, Darshan.K.R Lecturer,SJBIT Kengeri,Bangalore
Transcript
Page 1: Unit 1

UNIT -1 INTRODUCTION

Prepared By,

Darshan.K.R

Lecturer,SJBIT

Kengeri,Bangalore

Page 2: Unit 1

Darshan,S.J.B.I.T

The POSIX Feature Test Macros

1. _POSIX_JOB_CONTROL2. _POSIX_SAVED_IDS3. _POSIX_CHOWN_RESTRICTED4. _POSIX_NO_TRUNC5. _POSIX_VDISABLE

1. _POSIX_JOB_CONTROL :If this is defined on a system, then system supports the BSD style job control.

2. _POSIX_SAVED_IDS: If this is defined on a system, then each process runningOn the system keep the saved set UID & set GID, so that it can change its effectiveuserID & groupID to those values via setuid ad setgid API’s respectively

This features test macros are found in <unistd.h> header

Page 3: Unit 1

Darshan,S.J.B.I.T

The POSIX Feature Test Macros

3. _POSIX_CHOWN_RESTRICTED: If the defined value is -1 ,users may change Ownership of files owned by them .If the value is not -1 ,then only the users with special privileges may change theOwnership of nay files on a system. If this constant is undefined in <unistd.h> header,user must use the pathconf() Or fpathconf() function.

4._POSIX_NO_TRUNC : If the defined values is -1 ,any long pathname passed to an API is truncated to _POSIX_NAME_MAX bytes,otherwise any error is generated.If this constant is undefined in <unistd.h> header,user must use the pathconf() Or fpathconf() function.

5._POSIX_VDISABLE: If the defined value is -1 ,then there is no disabling character for special charactersfor all terminal devices files.If this constant is undefined in <unistd.h> header,user must use the pathconf() Or fpathconf() function.

Page 4: Unit 1

Darshan,S.J.B.I.T

Show test macros

#define _POSIX_SOURCE#define _POSIX_C_SOURCE 199309L#include <iostream.h>#include <unistd.h>int main(){

#ifdef _POSIX_JOB_CONTROLcout<<“System supports job control\n”;

#elsecout<<“System does not support job control\n”;

#endif . . . .

}

Page 5: Unit 1

Darshan,S.J.B.I.T

Limits checking at compile time and at run timePOSIX.1 & POSIX.1b define a set of system configuration limits in the form of Constant in <limits.h> header.

Compile time limit Value Meaning

_POSIX_NGROUP_MAX 0 Maximum number of supplement groups to which a process

may belong.

_POSIX_TZNAME_MAX 3 Maximum number of characters in a time zone name

_POSIX_CHILD_MAX 6 Maximum number of child processes that may created at any one time by a process

_POSIX_LINK_MAX 8 Maximum number of links a file may have

_POSIX_STREAM_MAX 8 Maximum number of I/O streams that may be simultaneously by a process

_POSIX_NAME_MAX 14 Maximum number of characters allowed in a filename

_POSIX_OPEN_MAX 16 Maximum number of file that may be opened simultaneously by a process

_POSIX_PATH_MAX 255 Maximum number of characters allowed in a pathname

_POSIX_MAX_INPUT 255 Maximum size in bytes of terminal’s input queue

_POSIX_MAX_CANON 255 Maximum size in bytes of terminal’s canonical input queue

_POSIX_ARG_MAX 4096 Maximum length of argument to the exec functions including environment data.

_POSIX_SSIZE_MAX 32767 Maximum value that can be stored in an object of type ssize_t.

Page 6: Unit 1

Darshan,S.J.B.I.T

POSIX.1B CONSTANTS

COMPILE TIME LIMIT VALUE MEANING

_POSIX_AIO_MAX 1 The number of simultaneously asynchronous I/O operations.

_POSIX_AIO_LISTIO_MAX 2 The number of I/O operations that can be specified in a list I/O call.

_POSIX_MQ_OPEN_MAX 2 The number of message queues that can be open for a single process.

_POSIX_MQ_PRIO_MAX 2 The maximum number of message priorities that can be assigned to messages

_POSIX_RTSIG_MAX 8 The maximum number of realtime signal .

_POSIX_TIMER_MAX 32 Maximum number of timers that can be used simultaneously number of

timers.

_POSIX_SIGQUEUE_MAX 32 Maximum number of realtime signals that a process may queue at any one time

_POSIX_DELAYTIMER_MAX 32 Maximum number of overruns allowed per timer.

_POSIX_SEM_NSEMS_MAX 256 Maximum number of semaphores that may be used simultaneously per process

_POSIX_SEM_VALUE_MAX 32767The maximum value a semaphore may have

Page 7: Unit 1

Darshan,S.J.B.I.T

sysconf, pathconf & fpathconf

To find out the actual implemented configuration limit system wide we can use sysconf,pathconf & fpathconf

The prototype of these functions are:

#include<unistd.h>long sysconf (const int limit_name);long pathconf (const char* pathname,int flimit_name);long fpathconf (const int fdesc,int flimit_name);

The sysconf is used to query general system configuration limits that are implemented on a given system.

The pathconf & fpathconf are used to query file-related configuration limits.

Page 8: Unit 1

Darshan,S.J.B.I.T

The possible limited value by the sysconf function

Limit value sysconf return data

_SG_ARG_MAX Maximum length of argument to the exec functions including environment data.

_SC_AIO_LISTIO_MAX The number of I/O operations that can be specified in a list I/O call.

_SC_AIO_MAX The number of simultaneously asynchronous I/O operations

_SC_CHILD_MAX Maximum number of child processes that may created at any one time by a process

_SC_CLK_TCK The number of clock ticks per second.

_SC_DELAYTIMER_MAX Maximum number of overruns allowed per timer

_SC_JOB_CONTROL The POSIX_JOB_CONTROL value

_SC_MQ_OPEN_MAX Maximum number of message queues per process

_SC_MQ_PRIO_MAX Maximum priority value assignable to a message

_SC_NGRUOP_MAX Maximum number of supplemental groups per process

Page 9: Unit 1

Darshan,S.J.B.I.T

LIMIT VALUE sysconf return Data

_SC_OPEN_MAX Maximum number of opened files per process

_SC_RTSIG_MAX Maximum number of real time signals

_SC_SAVED_IDS The _POSIX_SAVED_IDS value

_SC_SEM_NSEMS_MAX Maximum number of semaphores per process

_SC_SIGQUEUE_MAX Maximum number of realtime signals that a process may queue at any one-time

_SC_TIMERS The _POSIX_TIMERS Value

_SC_VERSION The _POSIX_VERSION value.

The possible limited value by the sysconf function

Page 10: Unit 1

Darshan,S.J.B.I.T

The possible limited value by the pathconf & fpathconf function

Limit value pathconf/fathconf return Data

_PC_CHOWN_RESTRICTED The _POSIX_CHOWN_RESTRICTED value.

_PC_LINK_MAX Maximum number of links a file may have

_PC_MAX_CANON Maximum size in bytes of terminal canonical input queue

_PC_MAX_INPUT Maximum size in bytes of terminal input queue

_PC_NO_TRUNC The _POSIX_NO_TRUNC value

_PC_NAME_MAX Maximum length in bytes of a file name.

_PC_PATH_MAX Maximum length in bytes of a pathname

_PC_PIPE_BUF Maximum size of a block of data that may be automatically read from or written to a pipe file

_PC_VDISABLE The _POSIX_VDISABLE value

Page 11: Unit 1

Darshan,S.J.B.I.T

The POSIX.1 FIPS standard

FIPS: Federal Information Processing StandardPOSIX.1 FIPS - Developed by NIST (National Institute of Standard and Technology)

Features to be implemented in all FIPS conforming systems

1. Job control :The symbol_POSIX_JOB_CONTROL must be defined.2. Saved setUID & setGID:The symbol _POSIX_SAVED_IDS3. Long path name is not supported but the symbol _POSIX_NO_TRUNC should be defined but it value should not be -14.The _POSIX_VDISABLE symbol value must be defined but its value should not be -15.The symbol _POSIX_ NGROUP_MAX should be defined with a value 86. Read and write APIs should return the no of bytes after the API is interruptedby signals.7.The Group ID of a newly created file must – Inherit that of the parent.8.The _POSIX_CHOWN_RESTRICTED must be defined but it value should not be -1

Page 12: Unit 1

Darshan,S.J.B.I.T

The X/Open Standards

X/Open organization was formed by a group of European companies to propose a common OS interface for their computing systems.

XPG3 – 1989XPG4 – 1994

COSE (Common Open software Environment) formed in 1993 by HP, IBM, Novell, OSF and Sun Microsystems

SPEC 1179Incorporated in XPG4 as part of X/Open Common

Application Environment

Page 13: Unit 1

Darshan,S.J.B.I.T

Unix & POSIX API”S

UNIX systems provides a set of application programming interface(API”S) functions commonly known as system calls which may be called user’s programs to performSystem specific functions. These fuctions allows user’s applications to directly to manipulate system objects such as files and processes that cannot be done by using standard C library functions.

Functions of API”S

1.Determine system configuration and user Infromation2.File Manipulation3.Process creation & control.4.Interprocess communication5.Network Communication

Page 14: Unit 1

Darshan,S.J.B.I.T

What happens when an API’s is called

When an API’s is invoked by a process,then execution context is switched by the kernel from a usermode to a kernel mode

User mode: is the normal execution context of any user process. It allows the process to access its process-specific data only.

Kernel mode: Is a protective execution environment that allows a user to access kernels data in a restricted manner.

In general ,calling an API is more time consuming than calling a user function due to Context switching

Page 15: Unit 1

Darshan,S.J.B.I.T

API COMMON CHARACTERISTICS

POSIX & UNIX API’s after performing the system functions returns an integer value which indicates the termination status of the execution.

If an API returns -1 value,it means the API’s execution has failed,& global variableDeclared in the <errno.h> header is set with an error code.

A user process may call the perror function to print a message of the failureTo the standard output. orIt may call the strerror function returns a message string & the user process mayPrint that message in its preferred way.

Page 16: Unit 1

Darshan,S.J.B.I.T

ERROR STATUS CODE

ERROR STATUS CODE Meaning

EACCESS A process doesn't have access permission to perform an operation via an API

EAGAIN An API was aborted because some system resource it requested was temporarily unavailable. So the API should be called again later

EBADF An API was called with an Invalid file descriptor

ECHILD A process doesnot have any child process which it can wait on

EFAULT An API was passed an invalid address in one of its argument

EINTR An API execution was aborted due to signal Interruption

EIO I/O error occurred in a API execution

ENOENT An invalid filename was specified to an API

ENOEXEC An AP Couldn't execute a program via of the exec API

EPERM An API was aborted because the calling process doesn't have the superuser privilege

EPIPE An API attempted to write data to a pipe which has no reader

ENOMEM An API was aborted because it could allocate Dynamic memory


Recommended