003 Linux System ProgrammingIssues, queries and suggestions related to Linux, Linux Programming, IPC, Interprocess Communication, Synchronization, Semaphore, System Programming, Linux Software Development.
System programming is the activity of programming system software. The systems programming aims to produce software which provides services to the computer hardware. It requires a greater degree of hardware awareness. We need to create an Inter Process Communication mechanism based client-Server setup. There should be a Server program, Some clients would send requests to the server and the server would further find the appropriate client to process the request. The server then invokes the new client so as to process the request. The new client should then send the result back to the server, which then sends it forward to the requesting client
hello , I made a single server-client communication and working fine. if i send a request to the server from a client ,it receive and further proceed to the operation such as addition and return the result to the server , and server send the result to the client all working fine but when i am using 3 clients then server read all three data correctly and process according to client need using fork ,exec and the result is returned back to the server but when the clients tries to read the data from the reading fifo (as i am using two fifo one common for writing and one for reading) they can read any data. result is correct but it is not going to its original client.
This is happening because all the clients are blocked on read and as soon as any data is available they start reading, the issue, is that the processor can randomly run any client so there's no saying which client reads what. Use signals to synchronize between the processes. Pause the client after writing the client data then kill the clients one by one using Kill system call. You can send the process pid via the structure that you're using to send the client request.
Yes, I use signal to synchronize the 3 process and it is working fine.I am using pipe.But when i run program 2-3 times then only once output comes fine.why it is so.
Hey Amardeep you are facing this problem as u must have included sleep in your program. Each time you run the program ur schedular schedules the process in a very undefined manner that you don't have control on. So I suggest u to not use the sleep. If still u are having problems then u must use Semaphores for synchronization
I made 3 clients using PIPES.Works fine. Unfortunately i had to use sleep() because i am using fork and execl to open the client and operation processes. So to avoid block on read/write i had to use sleep. Can i avoid such problem without using sleep??? sleep command is causing the program to run slow, does the work but i want it to be rapid.
Basic things regarding clients-server using circular buffers :
Never use sleep in your project, its not practical enough to give a delay intentionally when you want to run mealtime things
In order to have a proper synchronization between various processes sharing the same resource, signals can be of little help as to enable a particular PID to receive data from server.
But while reading the data from a a common pipe/FIFO, we need to use a semaphore in order to ensure that not all clients have access to the common resource as then they will end up screwing the input.
Every shared entity should always be placed within the critical section of P()and V() semaphores, where only atomic actions take place.
hello, I am using semaphore.In semctl i initialize the value of union semun val by 1. when i do the operation of semop and set the value of sem_op=-1. Then the val value is decrease or not. and what value is printing in critical section if we printed.
Doing the sem_op=-1 in the semaphore operation section will decrease the semaphore value which you initialized in the union structure during the semctl. It makes the sem variable value 0 means a process has acquired the critical region. After finishing things , semv function will be called which will again increment the semaphore variable value back to 1.
And about printing , Im not getting which value you want to print in the critical region.
what will happen if we send request from client to server through message queue rather than FIFO and taking result from vendor to server through shared memory rather than pipe.