Difference between revisions of "Operating Systems 2014F Lecture 3"

From Soma-notes
Jump to navigation Jump to search
Line 29: Line 29:




key role that init has to deal with are orphans. Child processes without a parent. When their parent is gone, init becomes their parent. There's something important about having a parent. Parents get the process id of the children. There is some kind of importance to the parent. What obligations unix places on parent processes. What is the use of a child to a parent. Why did you create a child? Multi CPU system - create another process, it can go off and do another computation on another cpu - doubles your power. But it's more than that. it can be used to do things that are potentially unsafe. Going to try parsing some file, that's been given to you by an untrusted source. If you do all of this stuff inside the main process, you can corrupt itself. There is a nuclear power plant -  
key role that init has to deal with are orphans. Child processes without a parent. When their parent is gone, init becomes their parent. There's something important about having a parent. Parents get the process id of the children. There is some kind of importance to the parent. What obligations unix places on parent processes. What is the use of a child to a parent. Why did you create a child? Multi CPU system - create another process, it can go off and do another computation on another cpu - doubles your power. But it's more than that. it can be used to do things that are potentially unsafe. Going to try parsing some file, that's been given to you by an untrusted source. If you do all of this stuff inside the main process, you can corrupt itself. There is a nuclear power plant - Star trek into darkness - whomever goes in there is going to die. Let the clone go in there, the unix solution to the kobayashi scenario. make a copy go in there.





Revision as of 09:00, 12 September 2014

Process API

Highly orthogonal - not only one way of doing things. Concept of Symbolic links, vs. hard links in Unix. In windows, there are about 5 different versions of links, and some of them work on some versions of windows. It's a complete mess.

They first introduced 1 api, that turned out to be bad w/ limited functionality. Evolution of windows - you look at their API and you get a mess.

ioctl - system call in unix / linux systems -an abomination - it doesnt' have well defined semantics - io control you give it the number of a device, and some arguments, and it varies from device to device as to what it does. In unix that is the exception. Most of the base stuff is clean. The people who worked at bell labs were smart, they created a system that they wanted to use for themselves.

In Unix, you don't call 1 call - you have 2 calls.

fork()

The classic structure of how to use fork:

if (fork()) {

} else {

}


Every call to fork returns two values. fork() always returns a process id and 0. After you call fork, you have two copies of your code running. What is in their memory? What files are open? - Exactly the same process, but you have two of them. That's why you always see a fork in a conditional, because you have 2 distinct processes running w/ exactly the same memory state, except for one difference:

if (pid=fork()) {
 // parent
} else {
 // child (pid = 0)
}


key role that init has to deal with are orphans. Child processes without a parent. When their parent is gone, init becomes their parent. There's something important about having a parent. Parents get the process id of the children. There is some kind of importance to the parent. What obligations unix places on parent processes. What is the use of a child to a parent. Why did you create a child? Multi CPU system - create another process, it can go off and do another computation on another cpu - doubles your power. But it's more than that. it can be used to do things that are potentially unsafe. Going to try parsing some file, that's been given to you by an untrusted source. If you do all of this stuff inside the main process, you can corrupt itself. There is a nuclear power plant - Star trek into darkness - whomever goes in there is going to die. Let the clone go in there, the unix solution to the kobayashi scenario. make a copy go in there.


execve(, , )

specific use cases for using both individually, without having to call both of them.