mirror of
https://github.com/riba2534/TCP-IP-NetworkNote.git
synced 2026-02-06 19:43:16 +08:00
26 lines
395 B
C
26 lines
395 B
C
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/socket.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
pid_t pid;
|
|
int sockfd = socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
pid = fork();
|
|
if(pid == 0)
|
|
{
|
|
printf("Child sockfd: %d \n", sockfd);
|
|
}
|
|
else
|
|
{
|
|
printf("Parent sockfd: %d \n", sockfd);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
结果:
|
|
Parent sockfd: 3
|
|
Child sockfd: 3
|
|
*/ |