My program was giving me an identifier removed error. I was going through the man page and I didn't understand what could cause this error "identifier removed". I've noticed that this happens everytime I try to send a message for the second time to a user process. The first time sending and recieving is fine. I tried a lot to reproduce a small example but I'm unable to. I don't think anyone here wants to go over so many lines of code. But basically what I am doing is
while(1)
{
if(messsage recieved from oss) //msg type getpid(), message text stores master pid
{
send message to oss //message type master pid, message text stores getpid()
}
}
the user process gets sent a message at random times like: time 1, time 4, time 8 etc.
The first time it sends and recieves its fine.
Identifier removed is the error message corresponding to error EIDRM. My system's man page for msgrcv says this error is returned for the following reason:
While the process was sleeping to receive a message, the message queue was removed.
A message queue is removed by passing command IPC_RMID to msgctl.
Related
After shutting down a socket in write mode, I am trying to write to the duplicated handle. I am getting broken pipe even though both of them have different file descriptors. What is wrong with my code ? or Is that expected behavior ?
int clientDupFD = dup(fileDescriptors[0]);
shutdown(fileDescriptors[0], SHUT_WR);
printf ("\n Client: Writing to shutdown(SHUT_WR) socket");
writeOk = write(clientDupFD, msgPtr="Writing message after partial shutdown!", 5);
if(writeOk == -1) {
printf("\n ERR-%s: write() failed to write msg to socket", strerror(errno));
}
else {
printf("\n Client: Message '%s' successfully written to socket", msgPtr);
}
Also, when I run this through CodeLite, complete output (last printfs) are not getting executed, why ?
Only when I try it through debugger, I can see that the "ERR-Broken pipe" printf statement was executing and the output got printed. I tried using 'fflush(stdout)' as well as 'setbuf(stdout, NULL)'. Both of them didnt work. Can anybody help ?
Once a connection's write direction has been shut down, writes can no longer take place on the connection and the implementation is free to communicate to the other end that no more data will arrive. It doesn't matter what handle you use to access the connection -- it's the same connection.
You have shutdown the FD (or more accurately the connection attached to both FDs), so consequently the write fails.
If you are trying to make a socket pair, use socketpair (or pipe).
I am running a sample MPI program which prints hello world.
When I am running with 1,2....330 process it runs as expected.
But when the number goes beyond 330 it fails with below error.
Can some explain the reason for this.
I am running the program on my laptop which has i5 processor with 4 cores and 8 GB RAM.
[proxy:0:0#Abhishek-Machine] HYDU_create_process (./utils/launch/launch.c:25): pipe error (Too many open files)
[proxy:0:0#Abhishek-Machine] launch_procs (./pm/pmiserv/pmip_cb.c:705): create process returned error
[proxy:0:0#Abhishek-Machine] HYD_pmcd_pmip_control_cmd_cb (./pm/pmiserv/pmip_cb.c:893): launch_procs returned error
[proxy:0:0#Abhishek-Machine] HYDT_dmxu_poll_wait_for_event (./tools/demux/demux_poll.c:77): callback returned error status
[proxy:0:0#Abhishek-Machine] main (./pm/pmiserv/pmip.c:206): demux engine error waiting for event
[mpiexec#Abhishek-Machine] control_cb (./pm/pmiserv/pmiserv_cb.c:202): assert (!closed) failed
[mpiexec#Abhishek-Machine] HYDT_dmxu_poll_wait_for_event (./tools/demux/demux_poll.c:77): callback returned error status
[mpiexec#Abhishek-Machine] HYD_pmci_wait_for_completion (./pm/pmiserv/pmiserv_pmci.c:197): error waiting for event
[mpiexec#Abhishek-Machine] main (./ui/mpich/mpiexec.c:331): process manager error waiting for completion
You are hitting an OS limit for socket descriptors or similar. Over subscribing your workstation to this degree is not a good idea and unlikely to work unless you change your system settings (which is not a good idea for this use case).
I am working on my first kernel module. I've completed a few exercises in The Linux Kernel Module Programming Guide but this is my first one without any guidance.
When I print messages using printk or the pr_err macro journalctl doesn't catch up until I print another message.
For example
int init_module()
{
pr_err("This is a message");
}
void cleanup_module()
{
pr_err("this is a second message");
}
If I insmod this module journalctl will show nothing. When I rmmod journalctl will show both messages and the timestamp will be the same.
If I insmod this module then insmod another module that prints both messages will show after I insmod the second module. The timestamp will be the same for both messages.
If message for printk doesn't contain newline symbol, its output can be delayed.
Normally, you need
pr_err("This is a message\n");
Sometimes, using KERN_INFO or KERN_ALERT also force message to be output immediately. But approach with terminating \n seems to be more clear.
Taken from answers to this question.
I have to use a fifo in my code.
I use sock to accept new client. For each client I create new thread to send and receive message to him.
In the function of the thread I use fifo to send and receive messages also to another process and here is my code:
int s_to_c=open(myfifo1,O_WRONLY);
int c_to_s=open(myfifo2,O_RDONLY);
char echoBuffer[RCVBUFSIZE];
int recvMsgSize;
for(;;)
{
bzero(echoBuffer,RCVBUFSIZE);
read(c_to_s, echoBuffer, RCVBUFSIZE);
write(sock, echoBuffer, strlen(echoBuffer));
bzero(echoBuffer,RCVBUFSIZE);
read(sock, echoBuffer, RCVBUFSIZE);
write(s_to_c,echoBuffer,strlen(echoBuffer));
}
close(c_to_s);
close(s_to_c);
close(sock);
And on the other side (The other process) my code:
int s_to_c=open(myfifo1,O_RDONLY);
int c_to_s=open(myfifo2,O_WRONLY);
char echoBuffer[RCVBUFSIZE];
int recvMsgSize;
for(;;)
{
bzero(echoBuffer,RCVBUFSIZE);
fgets(echoBuffer,RCVBUFSIZE,stdin);
echoBuffer[strlen(echoBuffer)-1]='\0';
write(c_to_s, echoBuffer, strlen(echoBuffer));
bzero(echoBuffer,RCVBUFSIZE);
read(s_to_c, echoBuffer, RCVBUFSIZE);
printf("%s\n", echoBuffer);
}
My problem is in this process : s_to_c and c_to_s take always the value(3,4).
So the first client connect correctly sending and receiving his message.
But when the second connect the first client become disable.And the messages of the second client sends and receives to and from the two processes.
Can I have some help please.Should I have to use tags for example??
select() allows you to check the status of a file descriptor (in your case the ones connected to your pipes). When select() returns, it tells you which pipes have data to process. That way, you can monitor many pipes in the server process.
The client process will always use the file descriptors 3 and 4 for the pipes since those are the first free ones after the stdio (0=stdin, 1=stdout, 2=stderr). So that is correct.
If you see the combination of 3 and 4 on your server as well, then you have a bug in the code where you create the pipes, not in the place where you use them.
If you use Linux, there is an easy way to see what a file descriptor is connected to: Look into /proc/PID/fd/ (replace PID with ID of the process that you want to examine) or use lsof -n -p PID (which shows a lot of other things as well like loaded shared libraries).
I am building a server client model in C. The clients connects to the server and they start exchanging data. However, the user can end the client at any time in the program, but the server is not notified about it. The server keeps sending that data even after the client is closed.
I was in the impression that send function will return -1 if the server is unable to send the data, but my server program just stuck at send
if((byteSent = send(new_fd, fileContents, strlen(fileContents), 0)) == -1){ //
the program just halts at the above line.
How do I overcome this problem?
//Code
exitT = 0;
//execution_count = 1;
for(i=0;i<execution_count;i++)
{
sleep(time_delay);
//getting the current time on the server machine
time_t t;
time(&t);
char *time=ctime(&t);
printf("The Execution time at server = %s\n",time);
system(exec_command);
/*Open the file, get file size, read the contents and close the file*/
// Open the file
fp = fopen(fileName,"r");
// Get File Size
fseek(fp,0,SEEK_END);
dataLength = ftell(fp);
rewind(fp);
fileContents = (char*)malloc(dataLength+1);
// Read File
fread(fileContents,1,dataLength,fp);
fileContents[dataLength] = '\0';
// Close file
fclose(fp);
printf("sockfd = %d \n",new_fd);
// send file length to client
rc=send(new_fd, &dataLength, sizeof(dataLength), 0) ;
printf("length of client data = %d \n",rc);
printf("sockfd = %d \n",new_fd);
// send time to client
rc=send(new_fd, time, strlen(time), 0) ;
printf("length of client time = %d \n",rc);
usleep(20000);
// Send file contents to Client
while(dataLength>0){
printf("sockfd = %d \n",new_fd);
if((byteSent = send(new_fd, fileContents, strlen(fileContents), 0)) == -1){
printf("bytes sent = %d \n",byteSent);
exitT = 1;
break;
}
dataLength-=byteSent;
}
//Delete the log file
sprintf(deleteCommand,"rm %s",fileName);
system(deleteCommand);
if(exitT == 1)
break;
}
bzero(fileName,sizeof(fileName));
bzero(exec_command,sizeof(exec_command));
bzero(deleteCommand,sizeof(deleteCommand));
//decClientNum();
kill(parent_id,SIGALRM);
close(new_fd); // parent doesn't need this
printf("STATUS = CLOSED\n");
exit(0);
}
Thanks
I assume you are coding for a Linux or Posix system.
When a syscall like send fails it returns -1 and sets the errno; you very probably should use errno to find out why it failed.
You could use strace to find out which syscalls are done by your sever, or some other one. Of course, use also the gdb debugger.
You very probably need to multiplex inputs or outputs. The system calls doing that are poll, select (and related ppoll and pselect). Read e.g. the select_tut(2) man page.
You may want to use (or at least to study the source code of) existing event oriented libraries like libevent, libev etc.. (Both Gtk and Qt frameworks provide also their own, which might be used even outside of GUI applications).
I strongly suggest reading about advanced unix programming and unix network programing (and perhaps also about advanced linux programming).
maybe you're using a tcp protocol and the server is waiting for an ACK. Try using udp if you want your connection to be asynchronous.
From the man page: No indication of failure to deliver is implicit in a send(). Locally detected errors are indicated by a return value of -1.
Proably something like this might help: http://stefan.buettcher.org/cs/conn_closed.html
I think I am pretty late in the party, but I think this answer might help someone.
If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does not have O_NONBLOCK set, send() shall block until space is available.
When send() function gets stuck, there might be a situation like, TCP window size has become 0. It happens when the other end of the connection is not consuming received data.
There might be a scenario like this, the receiving end process is running by GDB and segfault occurred.
The TCP connection remains established.
Data is being send continuously.
The receiver end is not consuming it.
Consequently the receiver TCP window size will keep decreasing and you can send data till it is greater than zero. Once it becomes 0, send() function will get stuck forever.
As the situation mentioned in the question is not a scenario of closed connection. When a process writes something on a closed TCP connection, it receives a signal SIGPIPE. Default handler of SIGPIPE terminates the process. So, in a closed connection scenario if you are not using your own SIGPIPE handler then process should be terminated by default handler whenever something is written on the socket.