shared memory doesn't get created

I'm building client-proxy-server application in C. Client sends request to proxy server for a file. Proxy server places filename in the shared memory and the server reads it. Server opens the file and puts the content of that file in shared memory for proxy server to read. Proxy server then sends this file back to client. I'm adding all the code here just so it is reproducible on individual's machine. Main point of focus is runSocket() function in proxy and in mainserver code. This is where shared memory is created and destroyed. Client side:

char buffer[65535]=""; 
char IP[200];  
char port[200];  

int sd;  
struct sockaddr_in client_sd;  

#define RESPONSE_RECV_LIMIT 3000
#define SOURCE_START_IDENTIFIER "<!DOCTYPE"
#define SOURCE_START_IDENTIFIER2 "<html>" 
 char response[RESPONSE_RECV_LIMIT+1]; 
        //this is the name of the identifier that the 
//#define FILENAME "/page2.html"                // ENTER THE FILENAME HERE
//#define PORT  "10000"
int sharedResource=0;
pthread_mutex_t mutex;  
void *execute();
void ex();
 // main entry point  
 int main(int argc, char* argv[])  
 {  
      //socket variables  
        // + 1 is for null
      printf("\nEnter proxy address:");  
      fgets(IP,sizeof("127.0.01\n")+1,stdin);  
      fputs(IP,stdout);  
      printf("\nEnter a port:");  
      fgets(port,sizeof("5000\n")+1,stdin);  
      fputs(port,stdout);  
      buffer[0]=0;
      if((strcmp(IP,"127.0.0.1\n"))!=0 || (strcmp(port,"5000\n"))!=0)  
      {  
           printf("Invalida proxy settings. Try again...");  
      }  
      else  
      {  

          int threads=0;
    printf("Enter number of threads you want to generate :D");
    scanf("%d",&threads);
    pthread_t* thread_pool= (pthread_t *) malloc(threads*sizeof(pthread_t));


    for(int i=0; i<threads;i++){
    printf("Type here:");  
    scanf("%s",&buffer);
   sleep(1);
     pthread_create(&thread_pool[i],NULL,execute,NULL);
     sleep(1);
    // pthread_join(thread_pool[i],NULL);


}
   for(int i=0; i<threads;i++){
    // pthread_create(&thread_pool[i],NULL,execute,NULL);
    pthread_join(thread_pool[i],NULL);


}

    free(thread_pool);
      }  
      return 0;  
 } 


void *execute(){

      ex();

} 

void ex(){


   // create a socket  
           if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0)  
           {  
                printf("socket not created\n");  
           }  
           memset(&client_sd, 0, sizeof(client_sd));  
           // set socket variables  
           client_sd.sin_family = AF_INET;  
           client_sd.sin_port = htons(5000);  
           // assign any IP address to the client's socket  
           client_sd.sin_addr.s_addr = INADDR_ANY;   
           // connect to proxy server at mentioned port number  
           connect(sd, (struct sockaddr *)&client_sd, sizeof(client_sd));  
           //send and receive data contunuously  


              // pthread_mutex_lock(&mutex);
                write(sd, buffer, sizeof(buffer));  
                printf("\nServer response:\n\n");  
                read(sd, buffer, sizeof(buffer));  
                fputs(buffer, stdout); 
                ///////////////////////////////////HTTP/////////////////////////////////////////

              if(send(sd,buffer,strlen(buffer),0) < strlen(buffer))
                      {
                         perror("Send Error!!\n");
                       }


             char *source;

             if( recv(sd,response,RESPONSE_RECV_LIMIT,0) == 0 )
                    {
                          perror("Recv : ");

                     }
            source = strstr(response,SOURCE_START_IDENTIFIER);

            if(source == NULL)
             {
                source = strstr(response,SOURCE_START_IDENTIFIER2);     
              } 
            printf("%s\n",source);
            printf("\n %d",sizeof(response));


            printf("\n");      



}

Proxy side:

#define SHMSZ 1024
char buffer[1024];  
int bytes =0; 
int hostname_to_ip(char * , char *);  
struct shared_data_t {

 pthread_mutex_t mutex;
 pthread_cond_t cond;
 char data[1024];
};


 // A structure to maintain client fd, and server ip address and port address  
 // client will establish connection to server using given IP and port   
 struct serverInfo  
 {  
      int client_fd;  
      char ip[100];  
      char port[100];  
 };  
 // A thread function  
 // A thread for each client request  
 void *runSocket(void *vargp)  
 {  


      struct serverInfo *info = (struct serverInfo *)vargp;  
      struct shared_data_t *buff = (struct shared_data_t *)vargp; 
      printf("client:%d\n",info->client_fd);  
      fputs(info->ip,stdout);  
      fputs(info->port,stdout);  
      //code to connect to main server via this proxy server  
      int server_fd =0;  
      struct sockaddr_in server_sd;  
      // create a socket  
      server_fd = socket(AF_INET, SOCK_STREAM, 0);  
      if(server_fd < 0)  
      {  
           printf("server socket not created\n");  
      }  
      printf("server socket created\n");       
      memset(&server_sd, 0, sizeof(server_sd));  
      // set socket variables  
      server_sd.sin_family = AF_INET;  
      server_sd.sin_port = htons(atoi(info->port));  
      server_sd.sin_addr.s_addr = inet_addr(info->ip);  
      //connect to main server from this proxy server  
      if((connect(server_fd, (struct sockaddr *)&server_sd, sizeof(server_sd)))<0)  
      {  
           printf("server connection not established");  
      }  
      printf("server socket connected\n");  

           //receive data from client  


                int shmid;
                key_t key;
                key_t sem_key;
                char *shm;
               struct shared_data_t *s=(struct shared_data_t *)vargp; 
            //pthread_mutex_lock(&mutex);
            memset(&buff->data, '\0', sizeof(buff->data));  
               pthread_mutexattr_t mutex_attr;
                pthread_mutexattr_init(&mutex_attr);
                pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED);
                pthread_mutex_init (&buff->mutex, &mutex_attr);

                pthread_condattr_t cond_attr;
                pthread_condattr_init(&cond_attr);
                pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED);
                pthread_cond_init (&buff->cond, &cond_attr);

                bytes = read(info->client_fd, buff->data, sizeof(buff->data));  
                char c;
                struct shared_data_t *entries;
           if(bytes <= 0)  
           {  
           }  
           else   
           {  



                printf("Redirecting to main server....!!!!");
               // printf("\n buff->data\n%s", buff->data);



                //naming shared memory segment 5678
                key=5678;

                //creating the segment
                if((shmid =shmget (key,1024,IPC_CREAT|0666))<0){
                         perror("shmget");
                         exit(1);
                }
                //attaching segment to our dataspace
                if((entries = (struct shared_data_t*)shmat (shmid,NULL, 0 )) == (char *) -1){
                         perror("shmat");
                         exit(1);
                 }

               // memset(entries, buff, sizeof( buff));
                //adding data to segment
                s= entries;

                printf("\n entries->data \n %s\n", entries->data);
                 pthread_mutex_lock(&buff->mutex);

                s->mutex= buff->mutex;
                 s->cond= buff->cond;
                 strcpy(s->data,buff->data);

               //////////////////////////////////////////////
                write(server_fd, "1", sizeof(buff->data));  
                fflush(stdout);  

              // strcpy(entries->data,NULL);
              //waiting for server to write something
          //   while(entries->data==buff->data)
            //       sleep(1);



               pthread_cond_wait(&s->cond, &s->mutex);

                // send response back to client  
              write(info->client_fd, s, sizeof(buff->data));  
               printf("From server :\n");                    
              fputs(entries->data,stdout); 
               pthread_mutex_unlock(&buff->mutex);}

   return NULL;  
 }  
 // main entry point  
 int main(int argc,char *argv[])  
 {  
     pthread_t tid;  
     char port[100],ip[100];  
     char *hostname = argv[1];  
     char proxy_port[100];  
        // accept arguments from terminal  
        strcpy(ip,argv[1]); // server ip  
        strcpy(port,argv[2]);  // server port  
        strcpy(proxy_port,argv[3]); // proxy port  
        //hostname_to_ip(hostname , ip);  
        printf("server IP : %s and port %s" , ip,port);   
        printf("proxy port is %s",proxy_port);        
        printf("\n");  
      //socket variables  
      int proxy_fd =0, client_fd=0;  
      struct sockaddr_in proxy_sd;  
 // add this line only if server exits when client exits  
 signal(SIGPIPE,SIG_IGN);  
      // create a socket  
      if((proxy_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)  
      {  
          printf("\nFailed to create socket");  
      }  
      printf("Proxy created\n");  
      memset(&proxy_sd, 0, sizeof(proxy_sd));  
      // set socket variables  
      proxy_sd.sin_family = AF_INET;  
      proxy_sd.sin_port = htons(atoi(proxy_port));  
      proxy_sd.sin_addr.s_addr = INADDR_ANY;  
      // bind the socket  
      if((bind(proxy_fd, (struct sockaddr*)&proxy_sd,sizeof(proxy_sd))) < 0)  
      {  
           printf("Failed to bind a socket");  
      }  
      // start listening to the port for new connections  
      if((listen(proxy_fd, SOMAXCONN)) < 0)  
      {  
           printf("Failed to listen");  
      }  
      printf("waiting for connection..\n");  
      //accept all client connections continuously  
      while(1)  
      {  
           client_fd = accept(proxy_fd, (struct sockaddr*)NULL ,NULL);  
           printf("client no. %d connected\n",client_fd);  
           if(client_fd > 0)  
           {  
                 //multithreading variables      
                 struct serverInfo *item = malloc(sizeof(struct serverInfo));  
                 item->client_fd = client_fd;  
                 strcpy(item->ip,ip);  
                 strcpy(item->port,port);  
                 pthread_create(&tid, NULL, runSocket, (void *)item);  
                 sleep(1);  
           }  
      }  
      return 0;  
 }  
 int hostname_to_ip(char * hostname , char* ip)  
 {  
   struct hostent *he;  
   struct in_addr **addr_list;  
   int i;  
   if ( (he = gethostbyname( hostname ) ) == NULL)   
   {  
     // get the host info  
     herror("gethostbyname");  
     return 1;  
   }  
   addr_list = (struct in_addr **) he->h_addr_list;  
   for(i = 0; addr_list[i] != NULL; i++)   
   {  
     //Return the first one;  
     strcpy(ip , inet_ntoa(*addr_list[i]) );  
     return 0;  
   }  
   return 1;  
 } 

Main server side:

#define CONNMAX 1000
#define SHMSZ 1024
#define BYTES 1024
pthread_t* thread_pool;
char *ROOT;
int listenfd, clients[CONNMAX];
void error(char *);
void startServer(char *);
void *respond(int);
 struct shared_data_t {

  pthread_mutex_t mutex;
  pthread_cond_t cond;
  char data[1024];
};

 // A thread function  
 // A thread is created for each accepted client connection  
 void *runSocket(void *vargp)  
 {  
   int c_fd =(int)vargp; // get client fd from arguments passed to the thread  
   char buffer[65535];  
   int bytes = 0; 
   char b[1024]="abc";
   char bb[1024];
   int counter=0; 
   char mesg[99999], *reqline[3], data_to_send[BYTES], path[99999];
   int rcvd, fd, bytes_read;
     struct shared_data_t *buff = (struct shared_data_t *)vargp;


           //receive data from client  
           memset(&buffer,'\0',sizeof(buffer));  
           bytes = read(c_fd, buffer, sizeof(buffer)); 
           if(!(bytes<0 && bytes==0 )){ 


          //SHARED MEMORY STUFF :) //

          for(int i=0; i<strlen(b);i++)
                printf("%c", b[i]);
          char c;
          int shmid;
          key_t key;
          struct shared_data_t *shm;
           struct shared_data_t *s;
          //naming shared memory segment 5678
          key=5678;
          //Locate the segment
          if((shmid =shmget (key,SHMSZ,0666))<0){
               perror("shmget");
               exit(1);
         }
          //attaching the segment
         if((shm =shmat (shmid,NULL,0))==(char *) -1){
               perror("shmat");
               exit(1);

         }
         int count=0;
         s =shm;
         printf("File name received is :\n");
         printf("%s\n",s->data);


          pthread_mutex_lock(&s->mutex);
          int handle = open(s->data, O_RDONLY);
             if (handle!=-1)    //FILE FOUND// change
                {




                    send(c_fd, "File found\n\n", 17, 0);
                                        //reading html file
                                        if(read(handle, s->data, 1024)!=-1)
                                                 printf("READ");
                                        //adding data to segment


                                s= shm;
                                        //*s->data= shared_buffer;
                            printf("%s",s->data);
                                        strcpy(shm->data,s->data);

                                       // printf("sharedddd %c",shared_buffer[i]);
                                        }
                                       //*s= NULL;



                else    {write(c_fd, " Not Found\n", 23); //FILE NOT FOUND
                                        }

             pthread_cond_signal(&s->cond);
             pthread_mutex_unlock(&s->mutex);


          }  


            fflush(stdout);  


 }  
 // main entry point  
 int main()  
 {  
      int client_fd;  
      char buffer[100];  
      int fd = 0 ;  
      struct sockaddr_in server_sd;  
 // add this line only if server exits when client exits  
 signal(SIGPIPE,SIG_IGN);  
      // create a socket  
      fd = socket(AF_INET, SOCK_STREAM, 0);  
      printf("Server started\n");  
      memset(&server_sd, 0, sizeof(server_sd));  
      // set socket variables  
      server_sd.sin_family = AF_INET;  
      server_sd.sin_port = htons(5010);  
      server_sd.sin_addr.s_addr = INADDR_ANY;  
      // bind socket to the port  
      bind(fd, (struct sockaddr*)&server_sd,sizeof(server_sd));  
      // start listening at the given port for new connection requests  
      listen(fd, SOMAXCONN);  
      // continuously accept connections in while(1) loop  
      while(1)  
      {  
           // accept any incoming connection  
           client_fd = accept(fd, (struct sockaddr*)NULL ,NULL);  
           //printf("accepted client with id: %d",client_fd);  
           // if true then client request is accpted  
           if(client_fd > 0)  
           {  
                 //multithreading variables    
                printf("proxy connected\n");     
                pthread_t tid;  
                // pass client fd as a thread parameter  
                 pthread_create(&tid, NULL, runSocket, (void *)client_fd);   
           }  
      }  
      close(client_fd);   
      return 0;  
 }  

This code works fine without the mutex and condition variables. But as soon as I put a lock on the code, mainserver produces this error

shmget:No such file or directory

Moreover, upon execution of second client thread proxy server produces the malloc error. In order to run this code execute in sequence in three different terminals:

gcc mainserver.c -o mainserver -lpthread
gcc proxy.c -o proxy -lpthread
./proxy 127.0.0.1 5010 5000
gcc client.c -o client -lpthread