Professional Documents
Culture Documents
National Institute of Technology, Delhi: END SEM Practical Exam
National Institute of Technology, Delhi: END SEM Practical Exam
DELHI
_____________________________________________________________
(c)
recvfrom():
#include<sys/socket.h>
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t
*addrlen)
sendto():
#include<sys/socket.h>
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,const struct sockaddr *dest_addr,
socklen_t addrlen)
(d) A zombie process is a process whose execution is completed but it still has an
entry in the process table. The zombie processes can be removed from the system by
sending the SIGCHLD signal to the parent, using the kill command. If the zombie
process is still not eliminated from the process table by the parent process, then the
parent process is terminated if that is acceptable.
(e) It suspends execution of the current process until one of its child process
terminates or a signal is received. After child process terminates, parent continues its
execution after wait system call instruction.
#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
int main()
{
char buffer[100];
char *message = "Hello Server.Thsi is your Client Pranshu";
int sockfd, n;
struct sockaddr_in servaddr;
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(PORT);
servaddr.sin_family = AF_INET;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
Output:
Server Side:
Code:
#include <stdio.h>
#include <strings.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include<netinet/in.h>
#define PORT 5000
#define MAXLINE 1000
int main()
{
char buffer[100];
char *msg = "Hello Pranshu";
int listenfd, len;
struct sockaddr_in servaddr, cliaddr;
bzero(&servaddr, sizeof(servaddr));
len = sizeof(cliaddr);
int n = recvfrom(listenfd, buffer, sizeof(buffer), 0, (struct sockaddr*)&cliaddr,&len);
buffer[n] = '\0';
puts(buffer);