lecture3 - CIS 525/725 Computer Networks Lecture 3:...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 525/725 – Computer Networks Lecture 3: Inter-Process Communication (IPC) and Synchronization Mitch Neilsen neilsen@ksu.edu
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics z UNIX Tutorial – http://www.cis.ksu.edu/~neilsen/unixtut/ z Putty Download Page http://www.chiark.greenend.org.uk/~sgtatham/putty/download. html z Process Model z Inter-Process Communication (IPC) z Process/Thread Synchronization z Application Programming Interfaces z Berkeley Sockets
Background image of page 2
Typical Uses of Fork z A shell (process) forks off slave(s) to execute a command so that the shell process can retain its original state after the command is executed; e.g., ksh, bash (Ex4.c). z A server forks off a slave (child process) to do the work, and the server continues processing new requests; e.g., Internet superserver ( inetd ).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
How many processes are created, including the parent? #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> main() { int i, retVal, status; for (i=1; i<=3; i++) { retVal = fork(); if (retVal == 0) { printf("In child %d, i = %d, retVal = %d.\n",getpid(), i, retVal); exit(0); } printf("In parent %d, retVal = %d.\n",getpid(), retVal); } for (i=1; i<=3; i++) { retVal = wait(&status); } } Example 4 processes, 1 parent, 3 children. In child 6120, i = 1, retVal = 0. In parent 6119, retVal = 6120. In child 6121, i = 2, retVal = 0. In parent 6119, retVal = 6121. In child 6122, i = 3, retVal = 0. In parent 6119, retVal = 6122.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
How many processes are created, including the parent? #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> main() { int i, retVal, status; for (i=1; i<=3; i++) { retVal = fork(); if (retVal == 0) { printf("In child %d, i = %d, retVal = %d.\n",getpid(), i, retVal); // exit(0); } printf("In parent %d, retVal = %d.\n",getpid(), retVal); } for (i=1; i<=3; i++) { retVal = wait(&status); } } Example 8 processes, 1 parent, 3 children, 3 grandchildren, 1 great-grandchild. In child 6262, i = 1, retVal = 0.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

lecture3 - CIS 525/725 Computer Networks Lecture 3:...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online