SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
TCP Server
socket()
bind()
listen()
accept()
TCP Client
socket()
connect()
Connection Established
Block until connection from client
write()
read()
read()
Process Request
write()
close() read()
close()
Data Request
Data (reply)
end-of-file notification
Socket Function
• To perform network I/O .
• Family specifies the protocol family.
 The connect function is used by a TCP client to
establish a connection with a TCP server:
 Sockfd is a socket descriptor returned by the socket
function
 Second & Third arguments are a pointer to the socket
address structure and its size.
The socket address structure must contain –
 IP address
 Port number
The client does not have to call bind.
The kernel chooses both an temporary port
and the source IP address if necessary.
Connection Error
ClientTCP
No Response
ETIMEDOUT
ECONNREFUSED Server’s response to client’s SYN is a reset
EHOSTUNREACH Host is down.
• Assigns a local protocol address to a socket.
• With IP, the protocol address is the combination of 32-bit IPv4 or
128-bit IPv6 address, along with a 16-bit TCP or UDP port
number.
#include <sys/socket.h>
int bind(int sockfd, const struct sockaddr *myaddr,
socklen_t addrlen);
•Servers bind to their well-known port when they
start.
•A process can bind a specific IP address to its socket.
•A client does not bind an IP address to its socket .
• EACCES The address is protected.
• EADDRINUSE The given address is already in use.
• EBADF The sockfd is not a valid descriptor.
• EINVAL The socket is already bound to an address.
 The listen function is called only by a TCP server and it performs two
actions:
• Converts an unconnected (active) socket into a passive socket.
• Specifies the maximum number of connections .
#include <sys/socket.h>
int listen(int sockfd, int
backlog);
• Called after both the socket and bind function .
• Backlog - for a given listening socket, the kernel maintains 2
queues:
• An incomplete connection queue - Contains an entry for each
SYN that has arrived from a client .
• A completed connection queue, entry for each client with whom
3-way handshake has completed.
• Accept is called by a TCP server
#include <sys/socket.h>
int accept(int sockfd, struct sockaddr
*cliaddr, socklen_t *addrlen);
• The cliaddr and addrlen args are used to return
the protocol address .
• Fork() function is the only way in Unix to create a new process
#include <unistd.h>
pid_t fork(void);
• Called once but returnsTWICE
• Once in the parent process (returns child process id),
• and once in the child process (return of 0)
• Used for multitasking .
• The process want to handle another program .
• Used when multiple clients are accessing a single
server .
• fork() is used in such cases to handle each client.
• Used to close a socket and terminate a TCP
connection
#include <unistd.h>
int close(int sockfd);
• Socket descriptor is no longer usable to the app
process.
Elementary TCP Sockets

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

User datagram protocol
User datagram protocolUser datagram protocol
User datagram protocol
 
TCP/IP
TCP/IPTCP/IP
TCP/IP
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
 
Chapter 2 - Network Models
Chapter 2 - Network ModelsChapter 2 - Network Models
Chapter 2 - Network Models
 
19 Network Layer Protocols
19 Network Layer Protocols19 Network Layer Protocols
19 Network Layer Protocols
 
Arp and rarp
Arp and rarpArp and rarp
Arp and rarp
 
ICMP
ICMPICMP
ICMP
 
User datagram protocol (udp)
User datagram protocol (udp)User datagram protocol (udp)
User datagram protocol (udp)
 
System call (Fork +Exec)
System call (Fork +Exec)System call (Fork +Exec)
System call (Fork +Exec)
 
Sockets
SocketsSockets
Sockets
 
Framing in data link layer
Framing in data link layerFraming in data link layer
Framing in data link layer
 
Internet control message protocol
Internet control message protocolInternet control message protocol
Internet control message protocol
 
Transportlayer tanenbaum
Transportlayer tanenbaumTransportlayer tanenbaum
Transportlayer tanenbaum
 
TCP congestion control
TCP congestion controlTCP congestion control
TCP congestion control
 
Token bus
Token busToken bus
Token bus
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Ch 19 Network-layer protocols Section 1
Ch 19  Network-layer protocols Section 1Ch 19  Network-layer protocols Section 1
Ch 19 Network-layer protocols Section 1
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control Protocol
 

Andere mochten auch

Andere mochten auch (12)

Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
14 M-CARE: Tükenmişlik Sendromunu Önleme
14 M-CARE: Tükenmişlik Sendromunu Önleme14 M-CARE: Tükenmişlik Sendromunu Önleme
14 M-CARE: Tükenmişlik Sendromunu Önleme
 
Lawrence
LawrenceLawrence
Lawrence
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Transport Layer
Transport LayerTransport Layer
Transport Layer
 

Ähnlich wie Elementary TCP Sockets

Socket programming using C
Socket programming using CSocket programming using C
Socket programming using CAjit Nayak
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxRockyBhai46825
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in CDeepak Swain
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptIntroduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptMajedAboubennah
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbPRADEEPERUKULLA2
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptssuserec53e73
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjPRADEEPERUKULLA2
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
Eshcol tech solutions pvt ltd
Eshcol tech solutions pvt ltdEshcol tech solutions pvt ltd
Eshcol tech solutions pvt ltdOjas Kumar
 
CODE FOR echo_client.c A simple echo client using TCP #inc.pdf
CODE FOR echo_client.c A simple echo client using TCP  #inc.pdfCODE FOR echo_client.c A simple echo client using TCP  #inc.pdf
CODE FOR echo_client.c A simple echo client using TCP #inc.pdfsecunderbadtirumalgi
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.pptEloOgardo
 

Ähnlich wie Elementary TCP Sockets (20)

Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
 
Sockets
Sockets Sockets
Sockets
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
socket programming
 socket programming  socket programming
socket programming
 
socket programming
socket programming socket programming
socket programming
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in C
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Introduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.pptIntroduction to sockets tcp ip protocol.ppt
Introduction to sockets tcp ip protocol.ppt
 
L5-Sockets.pptx
L5-Sockets.pptxL5-Sockets.pptx
L5-Sockets.pptx
 
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jbCN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
CN_UNIT4.ppt notre knxckvj bjbDJKVHFL jb
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Basics of sockets
Basics of socketsBasics of sockets
Basics of sockets
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
 
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjjCN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
CN_UNIT4.ppt ytutuim jykhjl fjghkhj gjjj
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Eshcol tech solutions pvt ltd
Eshcol tech solutions pvt ltdEshcol tech solutions pvt ltd
Eshcol tech solutions pvt ltd
 
Olumide pidan b
Olumide pidan bOlumide pidan b
Olumide pidan b
 
CODE FOR echo_client.c A simple echo client using TCP #inc.pdf
CODE FOR echo_client.c A simple echo client using TCP  #inc.pdfCODE FOR echo_client.c A simple echo client using TCP  #inc.pdf
CODE FOR echo_client.c A simple echo client using TCP #inc.pdf
 
Network Prog.ppt
Network Prog.pptNetwork Prog.ppt
Network Prog.ppt
 
Net Programming.ppt
Net Programming.pptNet Programming.ppt
Net Programming.ppt
 

Kürzlich hochgeladen

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 

Kürzlich hochgeladen (20)

React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 

Elementary TCP Sockets

  • 1.
  • 4. Socket Function • To perform network I/O . • Family specifies the protocol family.
  • 5.  The connect function is used by a TCP client to establish a connection with a TCP server:  Sockfd is a socket descriptor returned by the socket function  Second & Third arguments are a pointer to the socket address structure and its size.
  • 6. The socket address structure must contain –  IP address  Port number The client does not have to call bind. The kernel chooses both an temporary port and the source IP address if necessary.
  • 7. Connection Error ClientTCP No Response ETIMEDOUT ECONNREFUSED Server’s response to client’s SYN is a reset EHOSTUNREACH Host is down.
  • 8. • Assigns a local protocol address to a socket. • With IP, the protocol address is the combination of 32-bit IPv4 or 128-bit IPv6 address, along with a 16-bit TCP or UDP port number. #include <sys/socket.h> int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen);
  • 9. •Servers bind to their well-known port when they start. •A process can bind a specific IP address to its socket. •A client does not bind an IP address to its socket .
  • 10. • EACCES The address is protected. • EADDRINUSE The given address is already in use. • EBADF The sockfd is not a valid descriptor. • EINVAL The socket is already bound to an address.
  • 11.  The listen function is called only by a TCP server and it performs two actions: • Converts an unconnected (active) socket into a passive socket. • Specifies the maximum number of connections . #include <sys/socket.h> int listen(int sockfd, int backlog);
  • 12. • Called after both the socket and bind function . • Backlog - for a given listening socket, the kernel maintains 2 queues: • An incomplete connection queue - Contains an entry for each SYN that has arrived from a client . • A completed connection queue, entry for each client with whom 3-way handshake has completed.
  • 13.
  • 14. • Accept is called by a TCP server #include <sys/socket.h> int accept(int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen); • The cliaddr and addrlen args are used to return the protocol address .
  • 15. • Fork() function is the only way in Unix to create a new process #include <unistd.h> pid_t fork(void); • Called once but returnsTWICE • Once in the parent process (returns child process id), • and once in the child process (return of 0)
  • 16. • Used for multitasking . • The process want to handle another program .
  • 17.
  • 18. • Used when multiple clients are accessing a single server . • fork() is used in such cases to handle each client.
  • 19. • Used to close a socket and terminate a TCP connection #include <unistd.h> int close(int sockfd); • Socket descriptor is no longer usable to the app process.