16. If the shell recognizes the input as an internal command(like cd, for, while and others)
17. Executes the command internally without creating new processesElse Assumes that the command is the name of an executable file
18.
19. such aswho grep –n include *.c ls –l Shell forks and creates a child process. It execs the program that the user specified on the command line. The shell waits until the child process exits from the command and loops back to read the next command.
20. SHELL Algorithm /*read command line until “end of file” */ while(read(stdin,buffer,numchars)) { /*parse command line */ if(/*command line contains & */) amper=1; else amper=0; /*for commands not part of the shell command language */ if(fork()==0) { /*redirection of IO? */ if( /*redirect output */ ) { fd=creat(newfile,fmask); close(stdout); dup(fd); close(fd); /* stdout is now redirected */ }
21. SHELL Algorithm if( /* piping */ ) { pipe(fildes); if(fork()==0) { /* first component of command line */ close(stdout); dup(filedes[1]); close(filedes[1]); close(filedes[0]); /* stdout now goes to pipe */ /* child process does command */ execlp(command1,command1,0); } /* 2nd command component of command line */ close(stdin); dup(filedes[0]); close(filedes[0]); close(filedes[1]); /*standard input now comes from pipe */ }
24. Redirection of IO Child process has access to a copy of the shell command line after the fork. To redirect standard output to a file, nroff –mm bigdocument > output Child “creats” the output file specified on the command line if creat fails the child would exit immediately else child closes its previous standard output file and dups the file descriptor of the new output file. Standard output file descriptor now refers to the redirected output file. Child process closes the file descriptor obtained from creat to conserve file descriptors for the execed program. “Similar redirection occurs for standard input and standard error files”
37. Shell loops and reads the next commandRelationship of processes for ls=l|wc
38.
39. Administrator “boots” the system.Goal of the boot process: Get a copy of the operating system into machine memory Start executing it. It is usually done in a series of stages. Administrator may set switches on the computer console to specify the address of a special hardcoded bootstrap program Or just push a button that instructs the machine to load a bootstrap program from its microcode.
40.
41. Program in the boot block loads the kernel from the file system from the file /unix
42.
43. start Algorithm /* proc 0 continues here */ fork kernel process; /* process 0 invokes the swapper to manage the allocation of * process address space to main memory and the swap devices. * This is an infinite loop;process 0 usually sleeps in the * loop unless there is work for it to do */ execute code for swapper algorithm; }
44.
45. eg., Constructs linked list of free buffers and inodes, constructs hash queues for buffers and inodes, initializes region structures , page table entries and so on.
46. Then it mounts the root file system onto root (“/”) and fashions the environment for process 0
59. exec would have to parse file names in kernel space, not just in user space
60.
61. init Algorithm while((id= wait((int *) 0)) !=-1) { /* check here if a spawned child died * consider spawning it */ /* Otherwise, just continue */ }
62.
63. init reads the file “/etc/inittab” for instructions about which processes to spawn.
68. creates a process that executes the given program specificationsFor example, it may launch the getty(get teletype) processes to monitor the terminal lines configured n a system. When a user logs in, it goes through the login procedure and execs a login shell. Meanwhile, init executes a wait system call, monitoring the death of its child processes and the death of processes “orphaned” by exiting parents Sometimes in case of essential processes init may consider to respawn it.
71. Daemon Processes: Not associated with any users, but do system-wide functions, such as administration and control of networks, executing of time-dependent activities, line printer spooling and so on.