Domov technika System call

System call



Introductiontosystemcalls

Briefintroduction

ThemainfunctionoftheoperatingsystemistomanagehardwareresourcesandprovidegoodInordertoachievethisgoal,thekernelprovidesaseriesofmulti-kernelfunctionswithpredeterminedfunctions,whicharepresentedtousersthroughasetofinterfacescalledsystemcalls.Thesystemcallpassestherequestoftheapplicationprogramtothekernel,callsthecorrespondingkernelfunctiontocompletetherequiredprocessing,andreturnstheprocessingresulttotheapplicationprogram.

Modernoperatingsystemsusuallyhavemultitaskingfunctions,whichareusuallyimplementedbyprocesses.Sincetheoperatingsystemquicklyswitchesbetweeneachprocess,everythingwilllooklikeithappensatthesametime.Atthesametime,thisalsobringsalotofsecurityproblems.Forexample,aprocesscaneasilymodifythedataintheprocess'smemoryspacetomakeanotherprocessabnormalorachievesomegoals.Therefore,theoperatingsystemmustensurethateachprocesscanbeexecutedsafely.Thesolutiontothisproblemistoaddabaseaddressregisterandalimitregistertotheprocessor.Thecontentsofthesetworegistersusehardwaretolimittheaddressofthememoryaccessedbythememoryaccessinstruction.Inthisway,thecontentsofthesetworegisterscanbewrittentotheaddressrangeallocatedbytheprocesswhenthesystemswitchesprocesses,therebyavoidingmalware.

Inordertopreventtheuserprogramfrommodifyingthecontentsofthebaseaddressregisterandthelimitregistertoaccessothermemoryspaces,thesetworegistersmustbeaccessedthroughsomespecialinstructions.Generally,theprocessorhastwomodes:"UserMode"and"KernelMode".Atagbitisusedtoidentifywhatmodeitiscurrentlyin.Someinstructionssuchasmodifyingthecontentsofthebaseaddressregistercanonlybeexecutedinkernelmode,andthehardwarewillskipthisinstructiondirectlyandcontinuetoexecutethenextonewheninusermode.

Similarly,forsecurityreasons,someI/Ooperationinstructionsarerestrictedtoonlykernelmodecanbeexecuted,sotheoperatingsystemmustprovideaninterfacetoprovideapplicationssuchasreadingdatafromacertainlocationonthediskTheseinterfacesarecalledsystemcalls.

Whentheoperatingsystemreceivesthesystemcallrequest,itwilllettheprocessorenterthekernelmodetoexecuteinstructionssuchasI/Ooperationsandmodifythecontentsofthebaseaddressregister.Whenthesystemcallcontentisprocessed,Theoperatingsystemreturnstheprocessortousermodetoexecuteusercode.

PrinciplesofSystemCalling

Typesandstatesofprogramsinthesystem

Thestatesintheoperatingsystemaredividedintomanagementstate(corestate)andtargetstate(userstate).).Privilegedinstructions:atypeofspecialinstructionsthatcanonlyberuninthecoremodebutnotintheusermode.Privilegedinstructionsofdifferentoperatingsystemswillvary,butgenerallyspeaking,theyaremainlyhardware-relatedinstructions.Accesscontrolinstruction:itselfisaspecialinstruction,butnotaprivilegedinstruction.(Trapinstruction).Basicfunction:"Voluntaryadmission"cancauseabnormalvisitsandmanagement.

Theuserprogramonlyrunsintheusermode,andsometimesneedstoaccessthecorefunctionsofthesystem.Atthistime,thesystemcallisusedthroughthesystemcallinterface.

Systemfunctioncall

Systemfunctioncall:theuserusesthe"accessmanagementcommand"intheprogramtocallthesub-functionsetprovidedbytheoperatingsystem.Eachsystemsub-functioniscalledasystemcallcommand,alsocalledageneralizedcommand.

Systemcallinterface

Systemfunctioncallisaserviceprovidedbytheoperatingsystemtoprogrammers.Whenprogramming,programmerscanusesystemcallstorequesttheservicesoftheoperatingsystem.

Purpose:Tofacilitateusers'use.

Thedifferencebetweensystemcallandordinarycall

Systemcallisessentiallyakindofprocedurecall,butitisaspecialkindofprocedurecall,whichisdifferentfromprocedurecallingeneraluserprogram.obviousdifference.

Differentrunningstatus

Differentrunningstatus.Thecallingprocessandthecalledprocessofasystemcallrunindifferentstates,whileordinaryprocedurecallsgenerallyruninthesamestate.

Thecallingmethodisdifferent

Thecallingmethodisdifferent.Thesystemcallmustfirstenterthecoreofthesystemthroughthesoftinterruptmechanism,andthencanbetransferredtothecorrespondingcommandprocessingprogram.Ordinaryprocedurecallcanbedirectlytransferredfromthecallingprocesstothecalledprocess.

Backtoquestion

Returntoquestion.Inasystemthatusespreemptivescheduling,whenthesystemcallreturns,theschedulinganalysismustbeperformedagain-whetherthereisahigherprioritytaskready.Ordinaryprocedurecalldirectlyreturnstothecallingproceduretocontinueexecution.

Example:SystemcallinterfaceinLinuxoperatingsystem

Processcontrol

Forktocreateanewprocess

CloneiscreatedaccordingtospecifiedconditionsChildprocess

execverunexecutablefile

exitterminatetheprocess

_exitimmediatelyterminatethecurrentprocess

getdtablesizeThemaximumsizethattheprocesscanopenNumberoffiles

getpgidtogettheidentificationnumberofthespecifiedprocessgroup

setpgidtosettheidentificationnumberofthespecifiedprocessgroup

getpgrptogetthecurrentprocessgroupidentificationnumber

setpgrpsetsthecurrentprocessgrouplogonumber

getpidgetstheprocessidentificationnumber

getppidgetstheparentprocessidentificationnumber

getprioritygetstheschedulingpriority

setprioritysetstheschedulingpriority

modify_ldtreadsandwritesthelocaldescriptiontableoftheprocess

nanosleepsleepstheprocessforaspecifiedtime

nicechangesthepriorityofthetime-sharingprocessLevel

pausetosuspendtheprocessandwaitforthesignal

personalitytosettheprocessrunningdomain

prctltoperformspecificoperationsontheprocess

ptraceprocesstracking

sched_get_priority_maxtoobtaintheupperlimitofthestaticpriority

sched_get_priority_mintoobtainthelowerlimitofthestaticpriority

sched_getparamtoobtaintheschedulingparametersoftheprocess

sched_getschedulertoobtainTheschedulingstrategyofthespecifiedprocess

sched_rr_get_intervalGetthetimeslicelengthofthereal-timeprocessscheduledbytheRRalgorithm

sched_setparamSettheschedulingparametersoftheprocess

sched_setschedulerSetthespecifiedprocessSchedulingstrategyandparameters

Thesched_yieldprocesstakestheinitiativetogiveuptheprocessorandwaitsfortheendoftheschedulingqueue.

vforkcreatesachildprocessfortheexecutionofnewprograms,oftenwithexecve,etc.Atthesametimeuse

waittowaitfortheterminationofthechildprocess

wait3seewait

waitpidtowaitforthespecifiedchildprocesstoterminate

wait4seewaitpid

capgetgetsprocesspermissions

capsetsetsprocesspermissions

getsidgetsthemeetingidentificationnumber

setsidsetsthemeetingidentificationnumber

filereadandwriteoperations

fcntlFilecontrol

openopenfile

creatcreatenewfile

closeclosefiledescriptionword

readfile

writewritefile

readvreaddatafromfiletobufferarray

writevwritedatainbufferarraytofile

preadrandomfileRead

pwriterandomwritetofile

lseekmovefilepointer

_llseekmovefilepointerin64-bitaddressspace

dupcopyThedescriptionoftheopenedfile

dup2Copythedescriptionofthefileaccordingtothespecifiedconditions

flockfileadd/unlock

pollI/Omultipleconversion

truncatetruncatesthefile

ftruncateseetruncate

umasksetsthefilepermissionmask

fsyncwritesthepartofthefileinmemorybacktodisk

p>

Filesystemoperation

Accessdeterminesfileaccessibility

chdirchangescurrentworkingdirectory

fchdirseechdir

chmodchangefilemode

fchmodseechmod

chownchangefileownerorusergroup

fchownseechown

lchownSeechown

chrootchangerootdirectory

statfetchfilestatusinformation

lstatseestat

fstatseestat

statfsgetfilesysteminformation

fstatfsseestatfs

readdirreaddirectoryentries

getdentsreaddirectoryentries

mkdircreateDirectory

mknodcreateinode

rmdirdeletedirectory

renamefilerename

linkcreatelink

symlinkCreatesymboliclink

unlinkdeletelink

readlinkreadthevalueofsymboliclink

mountinstallfilesystem

umountremovefilesystem

ustatgetfilesysteminformation

utimechangefileaccessmodificationtime

utimesSeeutime

quotactlcontroldiskquota

systemcontrol

ioctlI/Ogeneralcontrolfunction

_sysctlread/writesystemparameters

acctenableordisableprocessaccounting

getrlimittoobtaintheupperlimitofsystemresources

setrlimittosettheupperlimitofsystemresources

getrusagetoobtainsystemresourceusage

uselibselectthebinaryfunctionlibrarytobeused

iopermsetportI/Opermission

ioplchangeprocessI/Opermissionlevel

outblow-levelportoperation

reboot

swaponopenswapfileanddevice

swapoffcloseswapfileanddevice

bdflushcontrolbdflushdaemon

sysfstakesthefilesystemtypesupportedbythecore

sysinfoobtainssysteminformation

adjtimexadjuststhesystemclock

alarmsettingprocessAlarmclock

getitimertogetthetimervalue

setitimertosetthetimervalue

gettimeofdaytogetthetimeandtimezone

settimeofdaytosetthetimeandtimezone

stimesetthesystemdateandtime

timegetthesystemtime

timesgettheprocessrunningtime

unnamegetthenameofthecurrentUNIXsystem,Versionandhostinformation

vhanguphangsthecurrentterminal

nfsservctlcontrolstheNFSdaemon

vm86enterssimulation8086mode

create_modulecreatesaloadablemoduleitem

delete_moduledeletesaloadablemoduleitem

init_moduleinitializemodule

query_modulequerymoduleinformation

*get_kernel_symsgetsthecoresymbols,whichhavebeenreplacedbyquery_module

Memorymanagement

brkChangedatasegmentspace

sbrkseebrk

mlockmemorypagelock

munlockmemorypageunlock

mlockallcallstheprocesstoaddallmemorypagesLock

Unlockallmemorypagesofthecallingprocessbymunlockall

mmapmappingvirtualmemorypage

munmapremovememorypagemapping

mremapremapvirtualmemorypageMemoryaddress

msyncwritesthedatainthemappedmemorybacktodisk

mprotectsetsmemoryimageprotection

getpagesizegetspagesize

syncWritememorybufferdatabacktoharddisk

cacheflushWritethecontentsofthespecifiedbufferbacktodisk

Network

getdomainnameGetdomainname

setdomainnamesetdomainname

gethostidgethostidentificationnumber

sethostidsethostidentificationnumber

gethostnamegetthishostname

sethostnamesethostName

Socketsocket

socketcallsocketsystemcall

socketestablishsocket

bindbindsockettoport

connectconnecttoremotehost

acceptrespondtosocketconnectionrequest

sendsendinformationthroughsocket

sendtosendUDPinformation

sendmsgSeesend

recvreceiveinformationthroughsocket

recvfromreceiveUDPinformation

recvmsgseerecv

listenlistensocketport

selecttopollmultiplesimultaneousI/Os

shutdowntoclosetheconnectiononthesocket

getsocknametoobtainthelocalsocketname

getpeernametoobtainthecommunicationpartnerSocketname

getockopttogetportsettings

setsockopttosetportparameters

sendfiletotransferdatabetweenfilesorports

socketpairtocreateaFortheconnectedunnamedsocket

UserManagement

getuidtoobtainuseridentificationnumber

setuidtosetuseridentificationnumber

getgidtoobtaingroupidentificationnumber

setgidsetgroupidentificationnumber

getegidgeteffectivegroupidentificationnumber

setegidseteffectivegroupidentificationnumber

geteuidgeteffectiveuseridentificationnumber

seteuidsetstheeffectiveuseridentificationnumber

setregidsetstherealandeffectivegroupidentificationnumberrespectively

setreuidsetstherealandeffectiveuseridentificationnumberrespectively

getresgidtoobtainthereal,effectiveandsavedgroupidentificationnumbersrespectively

setresgidtosetthereal,effectiveandsavedgroupidentificationnumbersrespectively

getresuidtoobtaintherealgroupidentificationnumbersrespectively,Validandsaveduseridentificationnumbers

setresuidsetsthereal,validandsaveduseridentificationnumbersrespectively

setfsgidsetsthegroupidentificationnumberusedwhencheckingthefilesystem

setfsuidsetstheuseridentificationnumberusedwhencheckingthefilesystem

getgroupsgetsthelistofsupplementarygroupflags

setgroupssetsthelistofsupplementarygroupflags

Inter-processcommunication

ipcInter-processcommunicationtotalcontrolcall

sigactionsetstheprocessingmethodforthespecifiedsignal

sigprocmaskexecutesthesignalinthesignalsetaccordingtotheparametersBlocking/unblockingandotheroperations

sigpendingsetsupaqueueforthespecifiedblockedsignal

sigsuspendsuspendstheprocesstowaitforaspecificsignal

signalseesignal

killsendsasignaltoaprocessorprocessgroup

*sigblockaddsasignaltotheblockedsignalmask,whichhasbeenreplacedbysigprocmask

*siggetmaskgetstheexistingblockedsignalmask,Hasbeenreplacedbysigprocmask

*sigsetmaskreplacestheexistingblockingsignalmaskwiththegivensignalmask,hasbeenreplacedbysigprocmask

*sigmaskconvertsthegivensignalintoamask,Hasbeenreplacedbysigprocmask

*sigpausehasthesamefunctionassigsuspend,andhasbeenreplacedbysigsuspend

sigvecisasignalprocessingfunctiondesignedforcompatibilitywithBSD,whichissimilartosigaction

ssetmaskANSICsignalprocessingfunction,similartosigaction

message

msgctlmessagecontroloperation

msggetgetmessagequeue

msgsndsendmessage

msgrcvgetmessage

pipe

pipecreatepipe

semaphore

semctlsemaphorecontrol

semgetgetasetofsemaphores

semopsemaphoreoperation

sharedmemory

shmctlcontrolsharingMemory

shmgetgetsharedmemory

shmatconnectsharedmemory

shmdtremovesharedmemory

Tento článek je ze sítě, nereprezentuje pozici této stanice. Uveďte prosím původ dotisku
HORNÍ