Unix and Posix Apis

You might also like

You are on page 1of 7

Context switching

When APIs is invoked by a process, the execution context of the process is switched by the kernel from a usermode to a kernel mode. A usermode is the normal execution context of any user process and it allows the process to access its process specific data only. A kernel mode is protective execution environment that allows a user process to access kernel!s data in a restricted manner. When the API execution completes the user process is switched back to the user mode. "his context switching for each API call ensures that process access kernel!s data in a controlled manner and minimi#es any chance of a run away user application may damage entire system.

Unix & POSIX Development Environment


<unistd.h> header declares commonly used POSIX. & U!IX "PIs. "lso speci#ic headers placed under <sys> under $usr$include$sys %eaders declare special data types #or data o&'ects manipulated &y &oth the "PIs and &y user processes. <stdio.h> header declares perror #unction (hich may &e called &y a user process (hen ever an "PI execution #ails. )he perror #unction prints a system*de#ined dia+nostic messa+e #or any #ailure incurred &y "PI.

POSIX. , POSIX. & and U!IX "PIs o&'ect code is stored in li&c.a and li&c.so li&raries

API COMMON CHARACTERISTICS


API return -1 to indicate the execution has failed Glo al !aria le errno is set "ith an error code in #error$h% Perror function &rints dia'nostic (essa'e of the error to the standard out&ut or calls streeror "ith errno as ar'u(ent

ERROR STAT)S CO*E $$ %&A'I'( EACCESS ++ No access to &erfor( an o&eration !ia a API EPERM ++ a API "as a orted ecause the callin' &rocess does not ha!e su&eruser &ri!ile'e ENOENT ++ an in!alid filena(e "as s&ecified to an API ,A*++ a API "as called "ith an in!alid file descri&tor EINTR ++ a API execution "as a orted due to si'nal interru&tion

EAGAIN

++ a API "as a orted ecause s.ste( resource it re/uested "as te(&oraril. una!aila le ENOMEM ++ a API "as a orted ecause it could not allocate d.na(ic (e(or. EIO ++ I0O error occurred in a API excecution EPIPE ++ a API atte(&ted to "rite to a &i&e "hich has no reader

E-A)1T ar'u(ents

++ a API "as &assed an in!alid address in one of its

ENOE2EC ++ a API could not execute a &ro'ra( !ia one of the exec API ECHI1* child ++ a &rocess doesnot ha!e an. &rocess "hich it can "ait on

You might also like