I try to launch an app within it's path and get it's process id:
(cd /opt/server/TrackServer/release && ./TrackServer&) && echo $!
but I always get wrong PID.
Ie i get:
$ (cd /opt/server/TrackServer/release && ./TrackServer&) && echo $!
5078
$ ps aux | grep TrackServer
user 5250 0.6 0.0 153340 7824 pts/0 S 20:09 0:00 ./TrackServer
user 5253 0.0 0.0 14868 976 pts/0 S+ 20:09 0:00 grep --color=auto TrackServer
how can I invoke the process within its path and get it's pid?
如果只有一个正在运行,使用pidof TrackServer
TrackServer
is a background process of the (...)
-induced subshell, not your script, so $!
in your script stores a different PID.
Try
pushd /opt/server/TrackServer/release && { ./TrackServer & echo $!; popd; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.