
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth look into processes in operating systems, covering the user-level view, implementation, and various system calls such as fork(), exec(), wait(), and exit(). It includes examples and explanations of concepts like process hierarchy, unix startup, and context switching.
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















User-level view of processes
Implementation of processes
setjmp/longjmp
class12.ppt
Introduction to Computer Systems
class12.ppt
runs concurrently with other processes (
multitasking)
managed by a shared piece of OS code called the
kernel
process^ – kernel is no t a separate pro cess, but rath er runs as part o f some user
each process has its own data space and process id (pid)
data for each protected protected from other processes Process A
Process B
user codekernel codeuser codekernel codeuser code
Time
class12.ppt
exits a process
void cleanup(void)atexit() function registers functions to be executed on exit
printf(“cleaning
(^) up\n”);
main() {} if (fork() == 0)atexit(cleanup);
printf(“hello
(^) from
(^) child\n”);
else {} printf(“hello
(^) from
(^) parent\n”);
exit();}
class12.ppt
main() {waits for a child to terminate and returns status and pid if (fork() == 0)int child_status;
printf(“hello
(^) from
(^) child\n”);
else {} printf(“hello
(^) from
(^) parent\n”);
printf(“childwait(&child_status);
(^) has (^) terminated\n”);
exit();}
CS 213 F’
class12.ppt
{
master_sockfd
(^) = sl_passivesock(port); /* create master socket
(^) */
while (1) { slave_sockfd
(^) = sl_acceptsock(master_sockfd); /* await request */
switch (fork()) { case 0: /* child closes its
(^) master and manipulates slave */
/* code to read and writeclose(master_sockfd);
(^) to/from slave socket goes here */
exit(0);
default: /* parent closes its copy of slave and repeats */ close(slave_sockfd);
case -1: /* error */ exit(0);fprintf("fork error\n");
}
}
}
class12.ppt
shell
child
child
child
grandchild
grandchild
init (1) (0)
e.g. snmpDaemon
class12.ppt
init [1] [0]
for the console forks a getty (get tty or get terminal)
getty
e.g. snmpDaemons/etc/inittab
the /etc/inittab file init forks new processes as per
class12.ppt
init [1] [0]
getty execs a login program
login
class12.ppt
while (read(stdin, buffer, /* read command line until EOF */
(^) numchars)) {
if (<command line contains ‘&’
(^) >)
amper (^) = 1;
else amper (^) = 0;
if (fork() == 0) {/* for commands not in the shell command language */} execl(cmd, cmd, 0)
if (amper == 0)} retpid
(^) = wait(&status);
}
class12.ppt
Reserved for kernel
Reserved for shared libraries Available for heapand dynamic loader
Heap (via malloc() or sbrk()
Grows up
Text segmentData segmentBss segment Stack
Available for stack Not accessible
Grows down to zero
Not accessible by convention
(64KB)
$sp $gp
0x (^0000) (^0000) (^0000)
0x (^0000) (^0000) (^) ffff
0x (^0000) (^0001) (^0000)
0x (^0000) (^) 1fff (^) ffff
0x (^0001) (^2000) (^0000)
0x (^) 03ff (^) 7fff (^) ffff
0x (^) 03ff (^8000) (^0000)
0x (^) 03ff (^) ffff (^) ffff
0x (^0400) (^0000) (^0000)
0xffff (^) fbff (^) ffff (^) ffff
0xffff (^) fc (^0000) (^0000)
0xffff (^) ffff (^) ffff (^) ffff
class12.ppt
interrupts
and exceptions
system calls (traps)
class12.ppt
expected program events
e.g., fork(), exec(), wait(), getpid()
call user-level library function,
switch from user mode to kernel mode
transfer control to kernel system call interface
find entry in syscall table corresponding to id
determine number of parameters
copy parameters from user member to kernel memory
save current process context (in case of abortive return)
invoke appropriate function in kernel
class12.ppt
user-level context
register context
system-level context.
text, data, and bss segments, and user stack
mode, kernel stack pointer, process table address, ...PC, general purpose integer and floating point regs, IEEE rounding
various OS tables process and memory tables, kernel stack, ...
the current process puts itself to sleep
the current process exits
when the current process returns from a system call
when the current process returns after being interrupted
context switch:
save current process context.
select new process (scheduling)
restore (previously save) context of new process
pass control to new process