Cse-Vi-Unix System Programming [10Cs62]-Solution
Total Page:16
File Type:pdf, Size:1020Kb
UNIX SYSTEM PROGRAMMING 10CS 26 UNIT-1 INTRODUCT OI N 1 .What si posix standard? Explain the diff tnere subset of posix standard. Write structure of program to filter out non-posix c mo pliant codes from su er program. 60( m )skra (DEC- 0102 ). Ans:The IEEE eicos ty formed a laiceps ksat fo ecr c la del POSI .X To c etaer a tes of sdradnats for epo r noita systems etni r af c nie g.sev lare bus stoor are POSIX.1,POSI b1.X AND POSI 1.X c POSI 1.X committee rp o sesop si dnats a dr for b esa OS API siht si dnats ra d eificeps s APIs rof manipulating selif a dn .ssecorp It si known sa IEEE 1.3001 - .0991 t eh POSI .X 1B committee esoporp s a s te fo nats d dra APIs of r RTOS fretni a ec th ese in edulc IPC. This is known sa IEEE nats dard 4.3001 - eht.3991 POSIX.1c dnats a dr ps e seific multi edaerht d programming tni e fr a ec . #define _POSIX_SOURCE #define _POSIX_C_SOURCE 03991 9L #include<iostream. >h #include<unistd.h> Int main )( { #ifdef _POSIX_VERSION Cout<<”System rofnoc ms ot sop ix”<<_POSIX_VERSION<<endl; esle# Cout<<”_POSIX_VERSION si enifednu d\n ;” fidne# Return 0; } 2.Write a pro rg am c or c++ posix com lp ement program ot hc e kc f llo owing il m sti : i)number of kcolc cit ks ii)Maximum n umber of child processes iii)Maximum path length iv)Maximum number fo characters in file name v)Maximum number o f open f seli per process. 80( m )skra Dec /9002 M ya 02 21 Ans: #define _POSIX_SOURCE Dept.of CS&E,SJBIT Page 1 UNIX SYSTEM PROGRAMMING 10CS 26 #define _POSIX_C_SOURCE 03991 9L #include<iostream. >h #include<unistd.h> Int main )( { I tn r ;se If(( =ser sy ocs nf(_SC_OPEN_MAX)==-1) orrep r “( sy ocs n )”f ; <tuoc esle <tuoc <”OPEN_MAX:”<< ser <<endl; er((fi s=pathconf(“/”,_PC_NAME_MAX)==- )1 orrep r tap“( h fnoc ” ;) esle cout<<”max_path name:<<(res+1)<< ;ldne If(( =ser sy nocs if(_SC_CLK_PCK)==-1) orrep r “( sy ocs n )”f ; <tuoc esle <tuoc < kcolc” :skcit ”<<res<< ;ldne er((fi s= sy fnocs (“/”,_SC_CH LI D_MAX)==- )1 orrep r “( sy ocs n )”f ; esle cout<<”max_childs:”<<(res+1)<< ;ldne er((fi s=pathconf(“/”,_PC_PATH_MAX)==-1) orrep r tap“( h fnoc ” ;) esle cout<<”max path name leng :ht < (< res+1)<< ;ldne 0 nruter 0 ; } 3.Explain the common characte scitsir o f API and describe the error s tatus codes 60( m )skra May 2009/May 2012 Ans: The APIs ruter n an tni e reg v eula ti idni c eta ht e termination sutats fo th rie ex fi.noituce na API snruter eulav -1 ti means API f delia dna eht labolg elbairav onrre si tes htiw na orre r resu.edoc p secor s se main llac eht roorep noitcnuf ot tnirp aid g citson messa eg fo uliaf re to dradnats tuptuo or ti may c lla ts r orre r uf n noitc a dn giv se ti e onrr sa a llavutc argument Dept.of CS&E,SJBIT Page 2 UNIX SYSTEM PROGRAMMING 10CS 26 ,eulav eht ts r rre or uf n noitc snruter mes as ge rts ing dna eht us re p secor s ot tnirp aht t message. oc sutats rorrE sutats oc ed meaning EACCESS a ssecorp seod ton ah ve sseca permission ot perform an A a aiv noitarepo aiv a A PI. EPERM a API w sa detrtoba eb ac esu eht nillac g rp o ssec t’seod vah e resurepus eht resurepus p gelivir e ENOENT an invalid file name w sa deificeps ot na A PI BADF A Api was c della htiw a n dilavni elif rotpircsed EINTR a A PI e xecution was abo detr eud ot a s ig lan etni rr noitpu EAGAIN a API was etroba d b suace e some sy ets m r cruose e ti deriuqer w sa temporarily anu vailable.The API dluohs eb dellac a niag retal . ENOMEM a API w sa detroba be ac u es ti dluoc ton etacolla dyanamic memory EIO I/O rre or cco u derr ni na API ex noituce EPIPE a A PI attempted to write data to pipre which h sa no daer re EFAULT a A PI was pass de na vni a dil sserdda ni eno fo sti arguments ENOEXEC a APi could not ex etuce a rp ogram via one fo eht ex ce A PI ECH LI D a ssecorp t’seod ah ve any dlihc orp c sse which ti nac wait .no .4 Bring out the importance of standardizing the UNIX OS. What aspects of c programming language ha ev been standardized ni ANSI ?c With ius table xe am lp e bring out the two i pm ortant id fference n/b K&R C and ANSIC w hti respect ot function prototyping a nd pointers to function. 80( m )skra Dec-09/May - .21 Ans: The IEEE eicos ty formed a laiceps ksat of r ec cal del POSI .X To c aer te a s te fo sdradnats rof epo r noita systems fretni a nic g. Sever la us b stoor ra e POSIX.1,POSI b1.X AND POSI 1.X c POSI 1.X committee rp o sesop si dnats a dr for b esa OS API siht si dnats ra d eificeps s APIs rof manipulating selif a dn .ssecorp It si known sa IEEE 1.3001 - .0991 t eh POSI .X 1B committee esoporp s a s te fo nats d dra APIs of r RTOS fretni a ec th ese in edulc IPC. This is known sa IEEE nats dard 4.3001 - eht.3991 POSIX.1c dnats a dr ps e seific multi edaerht d programming tni e fr a ec . The major aspe tc a r :e Dept.of CS&E,SJBIT Page 3 UNIX SYSTEM PROGRAMMING 10CS 26 x F noitcnu otorp ty ip ng x Support of the const and elitalov atad type ifilauq e sr x Support wide ahc r setca a dn ilanoitanretni z noita x Permit function pointers to be used without dere ef icner ng ANSI C stpoda uf n noitc otorp ty ip ng whe er uf cn noit noitinifed dna lced a noitar edulcni name,argument ad ta type dna nruter eulav d ata typ .e This en selba comliersto kcehc f ro noitcnuf sllac ni resu programs taht ssap dialvni .on fo ra guments ro incompatible argument data ty ep . F ro e xample Unsig den ol ng of o c( h ra * fmt,double data); ANSI C eificeps s taht fu noitcn retniop may be us de ekil uf n noitc name. No red e ef r iecne s n dedee wh ne illac ng a f noitcnu whose sserdda is deniatnoc ni a retniop . Example ht e following statement ed f eni a noitcnuf retniop rtpnuf which sniatnoc eht sserdda fo :oof noitcnuf :oof Ex nret diov elbuod(oof x y ,z tsnoc *tni ;)rtpl Void (*funcptr) ,elbuod( c tsno ni ;oof=)*t .5 Write a c++ program ot tsil the actual values of the follow ni g system configuration limits on a given unix OS. )i m xa imum no. of child processes that can be c detaer . )ii m xa imum no. of f eli s that can be opened simultaneously. )ii m xa imum no. of message queues that can be accessed. 60( m )skra Dec-10/May- .21 Ans: #define _POSIX_SOURCE #define _POSIX_C_SOURCE 03991 9L #include<iostream. >h #include<unistd.h> Int main )( { I tn r ;se If(( =ser sy ocs nf(_SC_OPEN_MAX)==-1) orrep r “( sy ocs n )”f ; <tuoc esle <tuoc <”OPEN_MAX:”<< ser <<endl; er((fi s=pathconf(“/”,_PC_NAME_MAX)==- )1 orrep r tap“( h fnoc ” ;) esle Dept.of CS&E,SJBIT Page 4 UNIX SYSTEM PROGRAMMING 10CS 26 cout<<”max_path name:<<(res+1)<< ;ldne If(( =ser sy nocs if(_SC_CLK_PCK)==-1) orrep r “( sy ocs n )”f ; <tuoc esle <tuoc < kcolc” :skcit ”<<res<< ;ldne er((fi s= sy fnocs (“/”,_SC_CH LI D_MAX)==- )1 orrep r “( sy ocs n )”f ; esle cout<<”max_childs:”<<(res+1)<< ;ldne er((fi s=pathconf(“/”,_PC_PATH_MAX)==-1) orrep r tap“( h fnoc ” ;) esle cout<<”max path name leng :ht < (< res+1)<< ;ldne 0 nruter 0 ; } 6. List the differences between ANSI C and K & R C.Explain 50( m skra ) May-06/Dec-06/May-08/Dec- 90 . Ans: The major diff ere n ec n/b ANSI C dna K&R C a er : x F noitcnu otorp ty ip ng x Support of the const and elitalov atad type ifilauq e sr x Support wide char setca a dn ilanoitanretni z noita x Permit function pointers to be used without ered ef icner ng ANSI C stpoda uf n noitc otorp ty ip ng whe er uf cn noit noitinifed dna lced a noitar edulcni name,argument ad ta type dna nruter eulav d ata typ .e This en selba comliersto kcehc f ro noitcnuf sllac ni resu programs taht ssap dialvni .on fo ra guments ro incompatible argument data ty ep . F ro e xample Unsig den ol ng of o c( h ra * fmt,double data); ANSI C eificeps s taht fu noitcn retniop may be us de ekil uf n noitc name. No red e ef r iecne s dedeen wh ne illac ng a f noitcnu whose sserdda is deniatnoc ni a retniop .