I'm writing a node.js application deployed through linkedin's glu platform.
The command to launch calls sudo -u <user> node app.js to start the node app as the right user, basically storing this command as a string and calling Groovy's exec() command on it.
The node app makes use of cluster to fork based of the number processors available, but basically it main job is to get some info and then launch a shell script via exec().
Sometimes the shell script will error out which is ok, but the problem is that when running under glu sometimes these shell scripts will become defunct on error, but should i start the node process through the terminal using sudo -u <user> node app.js, the process launches fine and the shell process get cleaned up properly.
What could cause the difference in behavior?
Yes, there is. One is being run in a shell, one is being executed directly. Things like piping, shell variables, command line options, etc. are all handled very different between running it in a shell and running it via the underlying Posix exec(3) and co. (i.e., using exec() in Java does not result in your process being run in a/the system shell.)
You need to use a Java equivalent of popen, run bash and execute your command as an argument, or something else along these lines.
One example of the latter with csh:
Process p = Runtime.getRuntime().exec(new String[]{"csh","-c","cat ~/myfile.txt"});