This line ran in a script
su --session-command="$javaCommandLine & >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1
pid="$(<$pidFile)"
echo $pid
The Pid is increased by one from the Pid the program ran by su really is.
How I do I get that program's pid?
I got a answer from serverfault stackexchange. by Daniel t.
@ https://serverfault.com/questions/563087/sh-bash-script-ambiguous-redirect-pid-of-file-using-single-quotes
Quoted:
The process ID is off by one because you have put an extra
&
after the$javaCommandLine
. In other words, you have put two processes in the background before callingecho $!
, thus getting the PID of>>$serviceLogFile 2>&1
rather than$javaCommandLine
. Those two pieces should be put in one, as the old 2 line codes showssu --session-command="$javaCommandLine & >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1
You might need to change it to -
su --session-command="$javaCommandLine >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments