-
Goal of processes:
- Multitasking (lots of apps at once)
- Performance
- Isolation
- Reliability
- Security (privacy on a multi-user system)
- How much isolation?
- Still want controlled comms. between processes
-
IPC
- Files
cat >f
head <f
- Message passing
cat | head
- Shared memory
- Issues: faster, so garbage, error and race errors
- Alter/control other processes
- Backdoors
-
Modeling OS resources
- OOP?
- No functional programming
struct $file\\to cpp
- Opaque file processes
- (Controlled file access)
int fstat(fd, struct stat *)
- Added protection, no races, but slow and complicated
-
int open(char const* element, flags, mode_t, mode)
O_RDONLY
O_WRONLY
O_RDWR
O_PATH
— what if want to open, but not read or write (check size)?
IO_CREAT
, over write, or create or don’t create if don’t exist
- On fail? returns -1, sets
errno
-
int close(int fd)
- Close fail, EBADF
char* strerror(int e)
-
ssize_t read(int fd, void* buf, size_t sizebuffsize)
- Returns 0 on EOF
- Returns 0 to buf size
-
ssize_t write(void const* buf)
-
off_t lseek(int fd, off_t offset, int whence)
- Whence:
- SEEK_SET: cur = offset
- SEEK_CUR: cur += offset
- SEEK_END: cur = filesize + offset
- On pipe? returns -1, errno set
-
pread
, pwrite
—same, but no lseek
-
Note that there is a distinction between storage and stream devices in API