Operating Systems 2019W Lecture 3: Difference between revisions

From Soma-notes
Created page with "==Video== Video from the lecture given on January 14, 2019 [https://homeostasis.scs.carleton.ca/~soma/os-2019w/lectures/comp3000-2019w-lec03-20190114.m4v is now available]...."
 
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:


==Notes==
==Notes==
===In Class===
<pre>
Lecture 3
---------
* tutorials have started
* look in cuLearn to see your TA
  - in grades, "TA" (feedback)
* system calls!
- we have processes
- they are isolated (only have a virtual CPU and virtual memory)
- to access any other resources, it must make a system call
  - system calls are requests to the kernel
- kernel decides whether a system call is allowed or not based on
  the user and group of the process
- file system calls
    open, read, write, lseek, (mmap), close
Question
- why do we only need to do GET, POST on the web, but we need to
  do a open before a read or write?
HTTP is (originally) stateless
- server doesn't have to remember client state between requests
UNIX file API is stateful
- maintains state between requests
file descriptors are an index into an array of file state maintained by the kernel for each process
---break---
SCS sysadmin in charge of openstack: Andrew Pullin
Processes can use file descriptors that were opened by "someone else"
- parent process
- "the one who execve'd me"
FORK:
process 4500
- opens file on fd 7
- runs fork, gets 4501
process 4501
- identical to 4500
- so has fd 7
EXECVE
process 5000
running /bin/bash
- opens file on fd 1
execve("/bin/ls")
- fd 1 still open for ls (running as process 5000)
</pre>
==Code==
===crash.c===
<source lang="c" line>
#include <stdio.h>
int main(int argc, char *argv[])
{
        int *x;
        x = (int *) 0;
        *x = 5;
        printf("Done!\n");
        return 0;
}
</source>

Latest revision as of 23:46, 14 January 2019

Video

Video from the lecture given on January 14, 2019 is now available.

Notes

In Class

Lecture 3
---------
* tutorials have started
* look in cuLearn to see your TA
  - in grades, "TA" (feedback)

* system calls!

 - we have processes
 - they are isolated (only have a virtual CPU and virtual memory)
 - to access any other resources, it must make a system call
   - system calls are requests to the kernel
 - kernel decides whether a system call is allowed or not based on
   the user and group of the process


 - file system calls
    open, read, write, lseek, (mmap), close

Question
 - why do we only need to do GET, POST on the web, but we need to
   do a open before a read or write?

HTTP is (originally) stateless
 - server doesn't have to remember client state between requests

UNIX file API is stateful
 - maintains state between requests

file descriptors are an index into an array of file state maintained by the kernel for each process

---break---

SCS sysadmin in charge of openstack: Andrew Pullin

Processes can use file descriptors that were opened by "someone else"
 - parent process
 - "the one who execve'd me"
 
FORK:
process 4500
 - opens file on fd 7
 - runs fork, gets 4501

process 4501
 - identical to 4500
 - so has fd 7


EXECVE

process 5000
running /bin/bash
 - opens file on fd 1
execve("/bin/ls")
 - fd 1 still open for ls (running as process 5000)

Code

crash.c

#include <stdio.h>

int main(int argc, char *argv[])
{
        int *x;

        x = (int *) 0;

        *x = 5;

        printf("Done!\n");

        return 0;
}