unix - Inside a bash script, how to get PID from a program executed when using the eval command? -
i have commands in bash script similar this:
eval "( java -classpath ./ $classname ${arguments[@]} $redirection_options $file )" & pid=$! however if ps $pid shows main script process instead of process of java program.
it obtains correct process when omit eval, in order of complicated arguments work correctly need use it.
any idea of how can pid of java program when it's executed within eval command?
your ampersand backgrounding eval line, causing (top-level) shell fork child, child shell eval string , in turn run java program grandchild of top-level shell. so, $! reports pid of child shell, backgrounded command.
instead move backgrounding inside eval:
eval "(java ...) &" pid=$! as long parenthetical doesn't complicated enough become subshell, above work.
Comments
Post a Comment