Is it good idea to run linux process in multi user environment.
Ex: Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("linux command"); int exitVal = proc.waitFor(); // may wait till 5 to 10 mins
Is it good idea to run linux process in multi user environment.
Ex: Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("linux command"); int exitVal = proc.waitFor(); // may wait till 5 to 10 mins
You need to be aware of some things:
If the process uses files, you must make sure that each process gets its own set or they will overwrite each others input/output. Use File.createTempFile()
.
The processes will run with the user rights of the server.
If the process gets data which the user can change in the browser, make sure that he can't send something like "; rm -rf /"
.
If the process runs more than a few seconds, you must run it in the background and parse the output to see when it completes. This can get hairy quickly because of error handling, you'll need to keeping a reference to the running process in the session, etc.
Other than that, there is no reason to be afraid of this. Unix is a server OS which is designed to run many, many processes at the same time :)
It's very bad idea.
Try to start process, but monitor them by watch-dog pattern with periodical ping from client browser
You haven't said enough about your run-time environment; though the question title mentions servlets and the question is tagged with servlet, you don't specify any specific run-time environment.
The answer to your question depends on very specific circumstances relating to your use case. For example, if you had a high-traffic site where access to any page would potentially spawn a new process which would run for some minutes, this does not sound like a good design, as any server might be easily brought down to a crawl in such a scenario. If, on the other hand, you have some specific long-running tasks which need to be run in a separate process and triggered via access to a web page where such access and process creation is controlled and deterministic, then it might be OK to do this. There is no actual technical obstacle.
Note that if you are using recent versions of Java, use of ProcessBuilder
is regarded as preferable to using the older Runtime.exec
.