I am using Mac. I have a c++ application, e.g. called myapp. Usually I can invoke the application, by ./myapp.
myapp application is capable of processing an image and returns some text result. Actually myapp application always has to allocate lots of memory at the beginning, so it is a bit slow if I have to run it multiple times.
Now I would like to do this
-
myapp will work as a service which is always running. I will start myapp at the very beginning by ./myapp.
-
when i have an image to process, I just want to type something like ./myapp arg1 arg2, here I don’t want to start a new process, I want to pass new arguments into the already running application and return results.
In order to make it, what should I do? I know myapp must contains a while loop which waits for requests. But how can I pass arguments during run time multitimes?
/*
It is something like e.g. ngix server. At the beginning you type ngix to start the service, and while it is running, you can still pass arguments by “ngix argument”, this command will not create a new process.
*/
/*
Actually I have a C++ image processing application and a python http server. Now what I do is, when the python server receives an image from a client, I start a new process by ./myapp imagelocation. myapp returns the processing results to the commandline and python captures it by “os.popen(“./myapp imagelocation,”r”).read().strip()”. but as I said, the C++ app takes too much time to initializes, so I want to initiaze it only once, and once I have an image, I just pass the image to the c++ app. Of course I know I can just let the C++ application to check if there is a new image saved, and call the method. But in this way, I cannot tell the python application the results */
Yes you can do what you want but you can’t use the command line arguments. They are passed just once to your program, when it is started. To wait for a request you can check some other stream, for instance a file or a pipe periodically for new data.