SystemCalls
- Check out these books
- Stevens Advanced Programming in the unix Environment
- Robins&Robins – unix systems programming
- Stevens Advanced Programming in the unix Environment
- Processes
- Fork
- Exec….
- Fork
- Files
- Open
- Close
- Read
- Write
- Lseek
- Dup
- Dup2
- Open
PerProcess file Descriptor table | System wide open file table | I-Nodes |
File descriptors | Flags | Disk / device |
0 | Offset | |
1 | To i-node | |
2 | ||
.. |
- Write(fd,buf,50)
- Fd
- File descriptor
- File descriptor
- Buf
- Void* char
- Void* char
- 50
- #bytes
- #bytes
- Write(fd,"Hello",6)
- If this was typed after the first line there would be an offset of 56
- If this was typed after the first line there would be an offset of 56
- Lseek
- Lseek(fd,offset,WHENCE)
- Fd
- File descriptor
- File descriptor
- Offset
- WHENCE
- SEEK_SET
- SEEK_CUR
- SEEK_END
- SEEK_SET
- Dup
- Duplicates a file descriptor using another file descriptor
- Int dup(int oldfd);
- Int dup2(int oldfd, int newfd)
- Int dup(int oldfd);
- Why would you want to do that?
- Because you would never want to do this
- Dup2(fd,1);
- First argument is one you want copied
- Second is what you want it copied on
- First argument is one you want copied
- Close(fd);
- Printf("hello\n";
- This would write at a file temp
int a[15]
int (*a)[15] /** a is a pointer to an array of 15 ints**/
int fd
fd = open("temp", _|_|_, 0660)
/*for the last input '0660' there should always be a leading 0 because it is an octal*/
/*_| represents space for flags*/
#define O_WRONLY 1<<4
O_TRUNK 1<<2
---------------------------------------
fd = open("temp", ..flag..)
write(fd,...)
close(fd)x
---------------------------------------
always check the return value from a system acall
if((fd = open("temp", ..flags..))<0){perror("...."); exit(1)}
for every file there exists an 'I-Node"
along with an I-Node there is a system-wide openfiletable
and with that there is a perprocess file descriptor table
No comments:
Post a Comment