Process Management System Calls in Linux System call Description id= fork( Create a child process identical to the parent pid= waitpid(pid, &statloc, opts) Wait for a child to terminate s= execve( name, argv, envp Replace a process' core image exit(status) Terminate process execution and return status S= sigaction(sig, &act, &oldact Define action to take on signals s= sigreturn(&context) Return from a signal s= sigprocmask(how, &set, &old) Examine or change the signal mask s=spending(set) Get the set of blocked signals s=sigsuspend( sigmask Replace the signal mask and suspend the process s= kill(pid, sig) Send a signal to a process residual alarm(seconds) Set the alarm clock s= pause() Suspend the caller until the next signal Figure 10-6. Some system calls relating to processes Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 10-6. Some system calls relating to processes. Process Management System Calls in Linux Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
A Simple Linux Shell while(TRUE)( /* repeat forever /* type_prompt() / display prompt on the screen * read__command(command, params /* read input line from keyboard * pid= fork () /* fork off a child process * if(pid <0)( printf("Unable to forkO) / error condition * continue: / repeat the loop *y if (pid l= O) waitpid(-1, &status, 0) / parent waits for child * else execve(command, params, O /* child does the work★/ Figure 10-7. A highly simplified shell Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 10-7. A highly simplified shell. A Simple Linux Shell Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of Processes and Threads The linux kernel internally represents processes as tasks, via the structure task struct Linux uses the task structure to represent an execution context A multithreaded process will have one task structure for each of the user -level threads The linux kernel itself is multi-threaded Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of Processes and Threads The Linux kernel internally represents processes as tasks, via the structure task_struct. • Linux uses the task structure to represent any execution context. • A multithreaded process will have one task structure for each of the user-level threads. • The Linux kernel itself is multi-threaded. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of Processes and Threads Categories of information in the process descriptor Scheduling parameters Memory image Signals · Machine registers System call state File descriptor table Accounting Kernel stack Miscellaneous Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of Processes and Threads Categories of information in the process descriptor: • Scheduling parameters • Memory image • Signals • Machine registers • System call state • File descriptor table • Accounting • Kernel stack • Miscellaneous Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Implementation of EXec P|D=501 P|D=748 P|D=748 New process sh Same process 1. Fork 4. sh overlaid created with Is Fork code Exec code Allocate childs task structure Find the executable program Fill childs task structure from parent Verify the execute permission Allocate childs stack and user area Read and verify the header Fill childs user area from parent Copy arguments, environ to kernel Allocate Pid for child Free the old address space Set up child to share parents text Allocate new address space Copy page tables for data and stack opy arguments, environ to stack Set up sharing of open files Reset signals Copy parent's registers to child Initialize registers Figure 10-8. The steps in executing the command Is typed to the shell Tanenbaum, Modern Operating Systems 3 e, (c)2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 10-8. The steps in executing the command ls typed to the shell. Implementation of Exec Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639