@ Parag Bafna was right in his answer when I conducted the test. However, I used a special kind of architecture on the server that could help with this. Take, for example, a command that takes a long time to run on the server. This can hang the server a bit and make it much slower for connections that need to be processed. Here is my solution.
Ask the client to call the asynchronous class method using the oneway property. Let me call it runProcess .
Make runProcess execute a popen() in the task and save the PID as a global variable.
Then use performSelectorInBackground to run the synchronous class method called readProcess in the background.
In readProcess I use while(fgets(buff, sizeof(buff), ghPID)!=NULL) to read the previously set popen() output (note the global variable ghPID ) and add the last line to the global variable of the last lines read. This method works as a background task, and the client is already disconnected from runProcess .
Now connect the client to a synchronous class method called getProcessData . Then it should take the global variable of the last lines and return it back. Since this does not take much time, the client quickly disconnects from this class method.
The client can then poll this data until it finds out about it. To help with this, you can create a synchronous method called isProcessRunning , which can check the global boolean variable on the server gbRunning called gbRunning and return true / false. Of course, you will have to flip this variable on the daemon server true / false in various class methods when the server is busy with the popen() task.
This way, your server daemon can respond to concurrent requests faster.
An additional tip would be to use the kill file or another mechanism (SIGHUP shared memory?), So if you are in a while loop and want to stop this process, you can simply delete the kill file somewhere in / tmp and the process will use pclose to kill it and then delete the kill file. I also do this before the start of the process, if I want only one specific process to run at a time with this server daemon.
source share