28:24 exec() and fork() system calls. So let's continue with this model where we said the shell itself is written as an application and the OS provides certain interfaces to allow the shell to start another program. so what are these interfces ? ans : fork() and exec() system calls. These sys calls are used to start another program. 34:04 Program - An executable on disk (it exists as an executable file on disk) Process - A running program The exec() system call converts a program to a process. 38:00 In fact, these system calls, fork() and exec() can be used by any application. In this model, the 'Shell' is just any other application and the kernel doesn't even know it's a 'Shell' or anything special, meaning, the system calls fork() and exec() can be just as well invoked from another application. So any application, when it calls fork() creates replica processes of the parent process. When it calls exec(), loads the file into the current process. (washing out the previous process, the one that called exec() ) 38:27 How to decide ? The programs returned by fork() are completely identical. How do you decide I'm the child and thus I should call exec() ( or exit() etc ) or I'm the parent and I should display the shell ? The fork() system call returns 2 processes. The child process behaves as if it has just returned from a fork() system call. fork() is a system call that is called by 1 process, but returns 2 processes, both at exactly the same program counter.BUT DIFFERENT pIDs (process IDs ). In the parent process, the return value of the fork() system call is the pID of the child. The child will return 0 ( or some number that cannot be a pID ). And that's your basis for distinguishing between the two processes and taking further action. The return value of the fork() system call is a pid. The return values are different for the parent and the child. For the parent process, the return value of fork() is the pid of the child. For the child process, the return value is some number that can't be a PID. sO all that a programmer needs to do is check the return value. If the return value (from fork() system call ) is 0, then I will call exec(). If the return value is non-zero, then I will call the print the next command prompt. 42:02 The formal code for the 'Shell' program. 45:18 Let's understand to implement the readCommand() in the shell. (high density gyaan from here til end. Watch full. gyaan includes - open, read, write, close interface exposed by UNIX system to manage access to shared resources. etc ) How smartly the OS designer has used the open(), read(), write(), close() system calls to read and write to the devices, and not just to the files.
It is not accurate to say fork creates two processes. It just creates a single process which is the child. The child is an exact replica of the parent process. Love this lecture a lot.
If fork() call returns exactly same copies, why does it matter which process is parent and which is child. They are the exact same copies. Let one call exec() and let other get stored to disk. Or am I missing something?
You need an information about which process is parent. This is because it's parent process's responsibility to kill the child process once job is done. If they don't get killed it becomes a zombie process. Zombie processes will take up lot of resources from your system. On the other hand, you also want parent process for wait to complete the child process. You don't want parent to kill the child before completing the task child was doing. This would defy the purpose of creating a fork() in first place. What exec() call will do is - it will replace the process created by fork(). You don't want child process to do same thing as parent. So exec() makes sense here. But again killing child process is responsibility of parent.
Linux programming interface. Author is person who maintained man pages for linux. For socket programming in c, Unix network programming socket api volume 1 edition 3
Haha, you'll need to be within All India Rank 100 (top 0.01 percent) in JEE, then only you stand a chance to get teachers like him. Just feel fortunate that NPTEL exists
Hi! I work for a company that is building an online learning platform. Your videos would be a perfect fit! Would it be possible to get an email ID where I can contact you for this?
Sorry, but however good a lecture this might be, I just cannot stand the speaker's mispronunciation of the word "fork". It's F O R K not fock. I don't mean to offend him, but that's just not the standard pronunciation.
American pronunciation is fork whereas the British pronunciation is fawk. In India we follow the British English as standard so i guess he's correct in that sense.
@@akhilmishra712 It might be technically correct, but in the conversations I've been a part of, being Indian, I've never heard it said like so. At the end of the day it doesn't matter.
it's okay, least see how educated he is!! u need to take a look at this thesoundofenglish.org/silent-r/ because I believe u need to understand phonetic urself and then only blame others