Posts

Showing posts from October, 2022

Part A-2

    Please go to this link to view the program https://docs.google.com/document/d/1WkpKdAsXef1ANVi0sPy329jd2oWSMFA2/edit?usp=sharing&ouid=115844831217705059666&rtpof=true&sd=true

Part B-3

  Program 3B:   CLIENT:   #include <stdio.h>   #include <sys/socket.h>   #include <netinet/in.h>   #include <string.h>   int main()   {           int clientSocket, portNum, nBytes;           char buffer[1024];           struct sockaddr_in serverAddr;           socklen_t addr_size;           clientSocket = socket(PF_INET, SOCK_STREAM, 0);           portNum = 7891;           serverAddr.sin_family = AF_INET;           serverAddr.sin_port = htons(portNum);           serverAddr.sin_addr.s_addr = inet_addr("127....

Part B-5

  pgm10s.c #include <unistd.h> #include <stdio.h> #include <sys/socket.h> #include <stdlib.h> #include <netinet/in.h> #include <string.h> #define PORT 8080 int main(int argc, char const *argv[]) {    int server_fd, new_socket, valread;     struct sockaddr_in address;     int opt = 1;     int addrlen = sizeof(address);     char buffer[1024] = {0};     char *hello = "Hello from server";   if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)     {         perror("socket failed");         exit(EXIT_FAILURE);     }      if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR,                      ...

Part B-4

Image
  Vi p9c.c #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h>   int main(){   int clientSocket, portNum, nBytes;   char buffer[1024];   struct sockaddr_in serverAddr;   socklen_t addr_size;     clientSocket = socket(PF_INET, SOCK_STREAM, 0);     portNum = 7891;     serverAddr.sin_family = AF_INET;   serverAddr.sin_port = htons(portNum);   serverAddr.sin_addr.s_addr = inet_addr("172.16.16.217");   memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);     addr_size = sizeof serverAddr;   connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);     while(1){     printf("Type a sentence to send to server:\n");     fgets(buffer,1024,stdin);     printf("You typed: %s",buffer);       nBytes = ...

Part B-2

  P6client.c #include<stdio.h> #include<stdlib.h> #include<errno.h> #include<string.h> #include<fcntl.h> #include<sys/types.h> #include<sys/stat.h> #include<unistd.h>   #define FIFO1 "fifo1" #define FIFO2 "fifo2"   int main()      {        char p[100], f[100], c[300];        int num, num2, f1,fd,fd2;            mknod(FIFO1, S_IFIFO | 0666, 0);        mknod(FIFO2, S_IFIFO|0666, 0);           printf("\n\n waiting for server......\n\n\n");           fd = open ( FIFO1, O_WRONLY);           printf("\n\n\n server online !! Enter the path .....\n\n");          wh...

Part B-1

  #include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h>   #define PERMS 0644 struct my_msgbuf {     long mtype;     char mtext[200]; };   int main(void) {     struct my_msgbuf buf;     int msqid;     int len;     key_t key;     system("touch msgq.txt");       if ((key = ftok("msgq.txt", 'B')) == -1) {        perror("ftok");        exit(1);   }       if ((msqid = msgget(key, PERMS | IPC_CREAT)) == -1) {        perror("msgget");        exit(1);     }     printf("me...

Part A-5

 Lab pgm:5 Write a program to create an integer variable using shared memory concept and increment the variable simultaneously by two processes. Use semaphores to avoid race conditions #include <sys/types.h> #include<sys/ipc.h> #include <sys/shm.h> #include <unistd.h> #include <string.h> #include <errno.h> int main(void) {    pid_t pid;    int *shared;    int shmid;    shmid = shmget(IPC_PRIVATE, sizeof(int), IPC_CREAT | 0666);    printf("shared Memory ID = %u",shmid);    if (fork() ==0) {        shared = shmat(shmid, (void *) 0, 0);        printf("child pointer %u \n", shared);        *shared=1;        printf("child value=%d \n", *shared);        sleep(2);        printf("child value=%d \n", *shared);       } else {           ...