Process and Threads - Operating Systems, Lecture Notes | CS 3204, Study notes of Operating Systems

Material Type: Notes; Professor: Ali; Class: Operating Systems; Subject: Computer Science; University: Virginia Polytechnic Institute And State University; Term: Fall 2003;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-82x
koofers-user-82x ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
๎˜
๎˜‚๎˜ƒ๎˜„๎˜…๎˜†๎˜‡๎˜‡๎˜†๎˜‡๎˜ˆ๎˜‰๎˜Š๎˜‹๎˜ˆ๎˜Œ๎˜๎˜ƒ๎˜†๎˜‰๎˜‹๎˜‡
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Process and Threads - Operating Systems, Lecture Notes | CS 3204 and more Study notes Operating Systems in PDF only on Docsity!

^

^ 

!^ "#

^

^ $%

^ 

^ ,

^ 0 

^ 

^ ^1 ^ %^  ^ 

^

^4 *

^ 

!^ "#

^

^ Process 1^ Process 2 User Space^ Process n-1^ Process n^ Operating System(kernel)

Globals/Static VariablesStack^ Heap Program Text(User Code + Libraries)

^ 

!^ "#

^

^ 

^8 

^1 -

^ #

^ 

^0 

^9 

^ 

^ ^ :^ 

^ ^ *

^ #^ 

^ 

&*^ 

^ :^6 

+^

^ 

^ 

^1 /;

^ #* 

^ 

^1 * 

^0 

^ 

!^ "#

^

^ 

^ 

 ^

1 ^ +! 

^

9 ^ ^ 

^ 

!^ "#

^

A

^ 

^ 

^ 0 

^ 

^   9 

^  

^9 

^  

PC (Thread 1)PC (Thread 2)PC (Thread 3) Globals/Static Variables^ Stack (Thread 1)^ Stack (Thread 2)^ Stack (Thread 3)^ Heap^ Program Text(User Code + Libraries)

^ 

!^ "#

^

C

^ ( 

^ 

.-/C

^  

^ 

^ 

^ 

^ *

status

^ 

!^ "#

^

^ =

^ 

^ ( 

^ 

^ int waitpid(pid, &status, options) ^ pid:

^ 

^ 

!^ "#

^

C;

int fds[2];retval

= pipe(fd);

^ ^ 

^ 

^ +

Process 1

Process 2 fd[0]

fd[1]

^ 

!^ "#

^

C

int^ fds[2]; char s[100];retval = pipe(fds);pid^ =^

fork();

if(pid != 0){ /* parent process /write(fds[1], โ€œhelloโ€, 6);} else^ { / child process */read(fds[0], s, 100);printf(โ€œRead %s\nโ€, s);}

^ 

!^ "#

^

^

+^1 - /

D

^  

^  

^ 

^ 

^ G

^ 

^ 

^ #

^ *

^ 

^ 

^

^ 

^ $gcc โ€“o firstthread firstthread.c-lpthread

^ 

!^ "#

^

^ =pthread_create

pthread_create(thread,attr,routine,arg) ^ thread

^ attr

 ^

^ routine

^  

^ 

  arg#

*^ 

^ 

^ 

^ 

+^ 

^ *

*^ 

*^ 

*^

^ *

^ 

!^ "#

^

B

^

C

void *PrintHello(void *threadid){ printf("%d: Hello World!\n", threadid);pthread_exit(NULL);} ^ pthread_exit(void *status):

=^ 

^ ^

status^

*H

^ 

!^ "#

^

C

^ pthread_join():

#^ 

^ #(

^