Ldflags
I am having problem with LDFALGS. how can i set these variables. I am getting a prob with Makefile also. If i am compiling my source file with cc than its working fine. but If i am doing this with Makefile than it says like "Fatal Error:stdio.h (all other also as i've tried) are not found".
what should i do??? please help... |
Hi,
sounds like your Makefile is a bit of a mess. If you post it here we might be able to help. Evo2. |
MakeFile
Thanks for this early relpy..
Please tell me difference b/w Linux Drivers makefile and Linux system prgrming make file I have created a UDP socket. Having one client and one server in one directory. and including header file is in another directory. like in include (mt_include.h) in source (server.c and client.c) Now how to make a Makefile my make file is like all: multithread LDFLAGS += -lpthread multithread: server.c client.c $(cc) $^ $(LDFLAGS) -o $@ #server:server.o #client:client.o |
Hi,
can you show me how you would compile this manually? Evo2. |
MakeFile
I can compile them on different tty. one server and client on another terminal. using
cc server.c and cc client.c |
Hi,
so you don't actually want to link pthread? Evo2. |
hey,
no no no ... its not like that...i have to link them..using -lpthread. actually i forgot to write that. |
Hi,
you say you've been able to get this to compile on the command line but you are having trouble with the Makefile. Since you have not provided with the code or the procedure for compiling on the command line I'd just be guessing if I tried to tell you what to put in your Makefile. Evo2. PS. This is begging to look like a homework problem. |
hahaha...yaa..
u can think like a homework problem. actually i am with Torres Network. Handling a dummy project I need to do all these things. thats why. but don't worry...i have resolved it now. I have made a Makefile. Both server and client source file are there. but i will not give them a combine name. ".o" file will be created and then i will execute them on different terminal. by d way..thanks for your response. really..thanks again. my Name is Pankaj Goyal and Basically I am fresher engineering graduate hired in this company for UNIX system Programming and Network Device Driver. |
Hi,
glad you were able to get this working. See you around LQ. Cheers, Evo2. |
hi..it will be very nice..can u plz explain me something abt thread affinity.
my server code is:- ////////////////////////////////////////////////////////////////////////////////////////////// //This file's code is serving as SERVER for Multi Threading Programe. Its having two threads// //data is transferring from main thread to thread1 and then from thread1 to thread2. For // //fulfilling the purpose of data transferring we are using shared memory. For communicating // //between two process we are using UDP server. And whichever packet client is sending will // //be saved to shared memory and used afterwards. // // // ///////////////////////////////////////////////////////////////////////////////////////////// #include "/home/torres/Desktop/Pankaj_Exercises/multi_thread/trial_multithread/include/mt_include.h" int main() { cpu_set_t cpuset1; int i; key=2; cl_size=sizeof(struct sockaddr_in); server.sin_family=AF_INET; //setting server attributes server.sin_port=htons(7000); //server.sin_addr.s_addr=inet_addr("127.0.0.1"); server.sin_addr.s_addr=INADDR_ANY; //printf("in Server\n"); //creating shared memory// shmid=shmget(key, 40, IPC_CREAT|0666); //Allocating shared memory of 40 bytes. if(shmid==-1) //shmget returns -1 on failure and zero on success { syslog(PRI, "Error in creatin Shared Memory at server side\n"); exit(EXIT_FAILURE); } else { ptr=(char*)shmat(shmid,NULL,0); //shared memory is pointing by pointer ptr which is a char pointer syslog(PRI,"Shared Memory is created with %d id\n", shmid); } //creating socket// sockid=socket(AF_INET, SOCK_DGRAM, 0); //an UDP socket is created. if(sockid==-1) //socket function also returns -1 on failure and socket id on success { syslog(PRI,"Problem in creating a socket at server side\n"); exit(EXIT_FAILURE); } else { int b=bind(sockid, (struct sockaddr*)&server, sizeof(server)); //binding to socket id if(b==-1) { syslog(PRI, "SERVER:Problem with Binding\n"); exit(EXIT_FAILURE); } else { syslog(PRI, "Socket bounded with local address\n"); printf("Press ! Ctrl+C to disconnect\n"); while(1) { ret=recvfrom(sockid, ptr, 40, 0, (struct sockaddr*)&client, &cl_size); //receiving from client if(ret==-1) { syslog(PRI, "Server not receiving\n"); exit(EXIT_FAILURE); } else { CPU_SET(0,&cpuset1); pthread_create(&PID1, NULL, thread1, ptr); //creating thread with PID1 and function thread1 pthread_setaffinity_np(PID1, sizeof(cpuset1), &cpuset1); pthread_join(PID1,(void**)&s); //joining of thread1 } } } } shmdt(ptr); //detaching the shared memory return 0; //returning } void * thread1(void *data) { cpu_set_t cpuset2; int end, *status; CPU_SET(1,&cpuset2); syslog(PRI,"Message from client=%s\n",data); printf("Message from client :- %s\n", data); pthread_create(&PID2, NULL, thread2, data); pthread_setaffinity_np(PID2, sizeof(cpuset2), &cpuset2); pthread_getaffinity_np(PID2, sizeof(cpuset2), &cpuset2); printf("affinity=%d\n",cpuset2); while(1) { pthread_join(PID2, (void**)&status); //joining thread 2 } pthread_exit(&end); //exiting from thread1 } void * thread2(void *data) { int bye; printf("Message to Client :- ", exBuff); fflush(stdin); //flushing the input buffer fgets(send_message,sizeof(send_message),stdin); strcpy(data,send_message); sendto(sockid, data, 40, 0, (struct sockaddr*)&client, sizeof(client)); //sending data to client syslog(PRI, "Message to Client=%s\n",data); pthread_exit(&bye); } client code is : ////////////////////////////////////////-----client.c---////////////////////////////////////////// // This file's code is serving as a client for our programme. Communication will be started by // // the client only. First it will send data through shared memory using UDP socket. Then after // // it will receive by server. This client-server will execute synchronously on different tty's // // /////////////////////////////////////////////////////////////////////////////////////////////// #include "/home/torres/Desktop/Pankaj_Exercises/multi_thread/trial_multithread/include/mt_include.h" int main() { int i; key=2; cl_size=sizeof(struct sockaddr_in); pthread_t PID1, PID2; //PID1 and PID2 are thread id's server.sin_family=AF_INET; server.sin_port=htons(7000); server.sin_addr.s_addr=INADDR_ANY; client.sin_family=AF_INET; //setting client and server attributes client.sin_port=htons(8000); //htons=host to network short client.sin_addr.s_addr=INADDR_ANY; //AF_INET used for domain. like internet ipv4 //inet_addr converts into binary format //creating shared memory// shmid=shmget(key, 40, IPC_CREAT|0666); //creating shared memory with same key so that client also can user this. if(shmid==-1) { syslog(PRI, "Error in creating Shared Memory at client section\n"); exit(EXIT_FAILURE); } else { ptr=(char*)shmat(shmid,NULL,0); //accessing shared memory with rd/wr mode. syslog(PRI, "Shared Memory is Created in client with %d id\n", shmid); } //creating socket// cl_sockid=socket(AF_INET, SOCK_DGRAM, 0); //an UDP socket is creating at client side with cl_sockid is the socket id if(cl_sockid==-1) { syslog(PRI,"Problem in Creating a socket at client side\n"); exit(EXIT_FAILURE); } else { syslog(PRI, "Socket is created in client\n"); int b=bind(cl_sockid, (const struct sockaddr*)&client, sizeof(client)); //binding to socket if(b==-1) { syslog(PRI, "Problem with bind in client\n"); exit(EXIT_FAILURE); } else { while(1) //loop will be continued till ctrl+C { printf(" Message to server :- "); fflush(stdin); fgets(send_message,sizeof(send_message), stdin); strcpy(ptr, send_message); ret=sendto(cl_sockid, ptr, 40, 0, (struct sockaddr*)&server, sizeof(server)); if(ret==-1) { syslog(PRI, "Server Not Receiving\n"); exit(EXIT_FAILURE); } else { syslog(PRI, "Message to server=%s\n",ptr); recvfrom(cl_sockid, ptr, 40, 0, (struct sockaddr*)&server, &serv_size); printf("Message from Server :- %s",ptr); } } } } return 0; //returning } |
All times are GMT -5. The time now is 07:08 AM. |