Operating Systems 2014F Lecture 3: Difference between revisions
No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
// parent | // parent | ||
} else { | } else { | ||
// child | // 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 - | |||
Revision as of 12:59, 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 -
execve(, , )
specific use cases for using both individually, without having to call both of them.