Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection.

Similar presentations


Presentation on theme: "Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection."— Presentation transcript:

1 Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection

2 System Calls Provide an interface between a process and the operating system. Generally available as assembly-language instructions UNIX system calls maybe invoked directly from a C or C++ program System calls for modern Microsoft Windows platforms are part of the Win32 application programmer interface (API), which is available for use by all the compilers written for Microsoft Windows

3 Example of how system calls are used… Consider writing a simple program to read data from one file and to copy them to another file What is the first thing the program needs? Which would be the process? Details in the lecture…

4 Passing parameters to the operating system The simplest approach is to pass parameters in registers. In some cases, there may be more parameters than registers. In these cases, the parameters are generally stored in a block or table in memory, and the address of the block is passed as a parameter ina register. This is the approach taken by LINUX. Parameters can also be placed, or pushed onto a stack by the program, and popped off the stack by the operating system. Some operating systems prefer the stack or block method, because they do not limit the number or length of parameters being passed.

5 Groups of system calls Process control –End, abort –Load, execute –Create process, terminate –Get, set attributes –Wait for time –Wait event, signal event –Allocate free memory File management –Create, delete file –Open, close –Read, write, reposition –Get, set file attributes Device management –Request, release device –Read, write –Get, set device attributes –Logically attch, detach devices Information maintenance –Get, set time/date –Get, set system data –Get, set process, file or device attribute Communications –Create, delete communciation connection –Send, receive messages –Transfer status information –Attach or detach remote devices

6 SYSTEM CALLS FOR THE FILE SYSTEM Return File Desc Use of nameiAssign inodes File Attributes File I/OFile Sys Structure Tree Manipulation open creat dup pipe close open stat creat link chdir unlink chroot mknod chown mount chmod mount creat mknod link unlink chown chmod stat read write lseek mount umount chdir chown

7 System Calls System calls that return file descriptors for use in other system calls System calls that use the namei algorithm to parse a path name System calls that assign and free inodes, using algorithms ialloc and ifree System calls that set or change the attributes of a file System calls that do I/O to and from a process, using algorithms alloc, free and the buffer application algorithms System calls that change the structure of the file system System calls that allow a process to change its view of the fiel system tree

8 OPEN The open system call is the first step a process must take to access the file open(pathname,flags,modes) Algorithm open Inputs: file name, type of open, file permissions (for creation type of open) Output: file descriptor { convert file name to inode (algorithm namei); if (file does not exist or not permitted access) return (error); allocate the file table entry for inode, initialise count, offset; allocate user file descriptor entry, set pointer to file table entry; if (type of open specifies truncate file) free all file blocks (algorithm free); unlock (inode); /*locked above in namei */ return (user file descriptor); }

9 Data structures after OPEN …………… …………… User file descriptor table inode tablefile table Count 1 Read Count 1 Rd-Wrt Count 1 Write Count 2 (/etc/passwd) Count 1 (local)

10 Data structures after two processes OPEN …………… …………… User file descriptor table (proc A) inode tablefile table Count 1 Read Count 1 Rd-Wrt Count 1 Write Count 2 (/etc/passwd) Count 1 (local) …………… …………… User file descriptor table (proc B) Count 1 Read Count 1 (private)

11 READ read (fd,buffer,count) algorithm read inputs: user file descriptor, address of buffer in user process, number of bytes to read output: count of bytes copied into user space { get file table entry from user file descriptor; check file accessibility; set parameters in u area for user address, byte count, I/O to user; get inode from file table; lock inode; set byte offset in u area from file table offset; while (count not satisfied) { convert file offset to disk block (algorithm bmap); calculate offset into block, number of bytes to read; if (number of bytes to read is 0) break; read block (algorithm breada if with read ahead, algorithm bread otherwise); copy data from system buffer to user address; update u area fields for file byte offset, read count, address to write into user space; release buffer; } unlock inode; update file table offset for next read; return (total number of bytes read); }

12 WRITE write (fd,buffer,count) Reading a file via two descriptors: #include main() { int fd1, fd2; char buf1[512], buf2[512]; fd1 = open(“/etc/passwrd”, O_RD); fd2 = open(“/etc/passwrd”, O_RD); read(fd1,buf1,sizeof(buf1)); read(fd2,buf2,sizeof(buf2)); }

13 Tables after CLOSING a file …………… …………… User file descriptors inode tablefile table Count 1 Count 2 (/etc/passwd) Count 1 (local) …………… …………… Count 1 Count 1 (private)

14 FILE CREATION algorithm creat input: file name, permission settings output: file descriptor {get inode for file name (algorithm namei); if (file already exists) { if (not permitted access) { release inode (algorithm iput); return (error); } } else/*file does not exist yet */ {assign free inode from file system (algorithm ialloc); create new directory entry in parent directory; include new file name and newly assigned inode number; } allocate file table entry for inode, initialise count; if (file did exist at time of create) free all file blocks (algorithm free); unlock (inode); return (user file descriptor); }

15 chdir, chroot chdir(pathname) chroot(pathname) chown(pathname, owner, group) chmod(pathname, mode)

16 PIPES Pipes allow transfer of data between processes in a FIFO manner. Named & unnamed pipes Pipe System call: pipe(fdptr) Opening a named pipe Reading and writing pipes Closing pipes

17 MOUNT - UNMOUNT The mount system call connects the file system in a specified section of a disk to the existing file system hierarchy The unmount system disconnects a file system from the hierarchy mount(special pathname, directory pathname, options) unmount(special pathname)

18 File System tree before and after Mount / bin etcusr ccdateshgettypasswd / bin includesrc awkbanneryaccstdio.h uts Root file system /dev/dsk1 file system

19 LINK - UNLINK The link system call links a file to a new name in the file system directory structure, creating a new directory entry for an exitsing node link(source file name, target file name) The unlink system call removes a directory entry for a file unlink(pathname)

20 FILE SYSTEM MAINTENANCE The kernel maintains consistency of the file system during normal operation. The command fsck checks for consistency and repairs the file system in case of extraordinary circumstances (power failure)


Download ppt "Operating system services Program execution I/O operations File-system manipulation Communications Error detection Resource allocation Accounting Protection."

Similar presentations


Ads by Google