0

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?

SSpoke
  • 165
  • 1
  • 3
  • 12
  • Please, don't cross-post. Since you have an accepted answer on SF, you should remove this Q. –  Dec 23 '13 at 18:08
  • Is it in the terms of service that I can't post the same question on 2 different forums? even though they are connected. Do you own the site or you are just a asshole trying to control people for no reason. If I post on both forums, which both have linux questions and they are both in a way server related, posting on both gets you more answers for free and more people look at them. So whats wrong about doing that? (they are both worded differently anyways). – SSpoke Dec 23 '13 at 20:10
  • What you did is IMHO cross-posting, which is not very appreciated here. Please see [this Meta Stack Overflow question which is about cross-posting.](http://meta.stackexchange.com/questions/64068/is-cross-posting-a-question-on-multiple-stack-exchange-sites-permitted-if-the-qu) And please try to be more polite, I'm not harassing you in any way, I'm just trying to be polite. –  Dec 23 '13 at 20:25

1 Answers1

1

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 calling echo $!, 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 shows

 su --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
SSpoke
  • 165
  • 1
  • 3
  • 12