Socket Programming Part 2 Sop, Fan 07302010028@fudan.edu.cn Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming
Sop, Fan 07302010028@fudan.edu.cn Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming
Topics ° Concurrency review Why should we use∴? Our experiences? Socket Programming related System requirement(robustness. How to cooperate with socket AP[? ° Example How to modify the example to fit further requirement?
Concurrency Review Why should we use …? Our experiences? Socket Programming related System requirement(robustness…) How to cooperate with socket API? Example How to modify the example to fit further requirement?
A scenario。。 Clients Server User 1 connect() accept( fgets() (goes to lunch Blocks read() User connect( Blocked
Clients User 1 (goes to lunch) Server connect() accept() fgets() User 2 read() connect() Blocked! Blocks!
How did we add concurrency Processes Uses forko Easy to understand(actually we have implemented one version A lot to consider about causing complexity(zombie, syscall.) e Threads Natural concurrency (new thread per connection) Easier to understand you know it already) Complexity is increased(possible race conditions) Use non- blocking I/O Uses select () Explicit control flow(no race conditions Explicit control flow more complicated though
Processes Uses fork() Easy to understand(actually we have implemented one version!) A lot to consider about causing complexity(zombie, syscall…) Threads Natural concurrency (new thread per connection) Easier to understand (you know it already) Complexity is increased (possible race conditions) Use non-blocking I/O Uses select() Explicit control flow (no race conditions!) Explicit control flow more complicated though
Multi-process Forko Use Pid to verify different process Assign different task flow accordingly Signal& waitpid(…) Tracing child processes, kill the zombies e Other process control methods?
Fork() Use Pid to verify different process Assign different task flow accordingly Signal & waitpid(…) Tracing child processes, kill the zombies Other process control methods?