The open() system call

The open() system call - The open() system call int...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
The open() system call int open(filename, mode, [permissions]), It opens the file in filename using the permissions in mode . Mode: O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_APPEND, O_TRUNC O_CREAT If the file does not exist, the file is created.Use the permissions argument for initial permissions. Bits: rwx(user) rwx(group) rwx (others) Example: 0555 – Read and execute by user, group and others. (101B==5Octal) O_APPEND. Append at the end of the file.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The close() System call void close(int fd) Decrements the count of the open file object pointed by fd If the reference count of the open file object reaches 0, the open file object is reclaimed.
Background image of page 2
The fork() system call int fork() It is the only way to create a new process in UNIX The OS creates a new child process that is a copy of the parent. ret = fork() returns: ret == 0 in the child process ret == pid > 0 in the parent process. ret < 0 error The memory in the child process is a copy of the parent process’s memory. We will see later that this is optimized by using VM
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The fork() system call The Open File table of the parent is also copied in the child. The Open File Objects of the parent are shared with the child. Only the reference counters of the Open File Objects are increased.
Background image of page 4
The fork() system call Open File Object Ref count=1 Open FileTable (parent)_ Ref count=1 Ref count=1 Before: 0 1 2 3
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The fork() system call Open File Object Ref count=2 Open FileTable (parent) Ref count=2 Ref count=2 After: 0 1 2 3 Open FileTable (child) 0 1 2 3
Background image of page 6
The fork() system call Implication of parent and child sharing file objects: By sharing the same open file objects, parent
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 23

The open() system call - The open() system call int...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online