How to make sure the pid file is removed when the corresponding process terminates?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I read some related posts . I tried it, but it does not work on functions defined in the script.
ssh someuser@host /path/to/scirpt.sh
the script on the remote machine:
#!/bin/sh
startup_cleanup_pid()
java SomeMainClass 1>somelog 2>&1 &
PID=$!
echo $PID > pid
wait $PID
rm pid
startup_cleanup_pid 1>/dev/null 2>&1 &
#startup_cleanup_pid & #this does not work either
echo "about to exit"
exit 0
I would like to detach the child process. How can I do that?
EDIT:
What I am trying to achieve:
1) When I used the ssh command ssh someuser@host /path/to/startup_java_process.sh and the above script, the ssh session did not terminate which I didn't know why. It just hanged there. I would like the ssh session to terminate when hitting exit 0 in that script.
2) When the java process somehow terminates, make sure the pid file is removed as well.
The link mentioned in the comment pretty much solved my problem.
linux shell ssh
 |Â
show 3 more comments
up vote
0
down vote
favorite
I read some related posts . I tried it, but it does not work on functions defined in the script.
ssh someuser@host /path/to/scirpt.sh
the script on the remote machine:
#!/bin/sh
startup_cleanup_pid()
java SomeMainClass 1>somelog 2>&1 &
PID=$!
echo $PID > pid
wait $PID
rm pid
startup_cleanup_pid 1>/dev/null 2>&1 &
#startup_cleanup_pid & #this does not work either
echo "about to exit"
exit 0
I would like to detach the child process. How can I do that?
EDIT:
What I am trying to achieve:
1) When I used the ssh command ssh someuser@host /path/to/startup_java_process.sh and the above script, the ssh session did not terminate which I didn't know why. It just hanged there. I would like the ssh session to terminate when hitting exit 0 in that script.
2) When the java process somehow terminates, make sure the pid file is removed as well.
The link mentioned in the comment pretty much solved my problem.
linux shell ssh
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh commandssh someuser@host /path/to/startup_java_process.shto terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.
â du369
Aug 31 at 5:08
1
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding<â¯/dev/nullon both lines where you are redirecting file descriptors 1 andâ¯2.
â G-Man
Aug 31 at 5:14
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
1
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13
 |Â
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I read some related posts . I tried it, but it does not work on functions defined in the script.
ssh someuser@host /path/to/scirpt.sh
the script on the remote machine:
#!/bin/sh
startup_cleanup_pid()
java SomeMainClass 1>somelog 2>&1 &
PID=$!
echo $PID > pid
wait $PID
rm pid
startup_cleanup_pid 1>/dev/null 2>&1 &
#startup_cleanup_pid & #this does not work either
echo "about to exit"
exit 0
I would like to detach the child process. How can I do that?
EDIT:
What I am trying to achieve:
1) When I used the ssh command ssh someuser@host /path/to/startup_java_process.sh and the above script, the ssh session did not terminate which I didn't know why. It just hanged there. I would like the ssh session to terminate when hitting exit 0 in that script.
2) When the java process somehow terminates, make sure the pid file is removed as well.
The link mentioned in the comment pretty much solved my problem.
linux shell ssh
I read some related posts . I tried it, but it does not work on functions defined in the script.
ssh someuser@host /path/to/scirpt.sh
the script on the remote machine:
#!/bin/sh
startup_cleanup_pid()
java SomeMainClass 1>somelog 2>&1 &
PID=$!
echo $PID > pid
wait $PID
rm pid
startup_cleanup_pid 1>/dev/null 2>&1 &
#startup_cleanup_pid & #this does not work either
echo "about to exit"
exit 0
I would like to detach the child process. How can I do that?
EDIT:
What I am trying to achieve:
1) When I used the ssh command ssh someuser@host /path/to/startup_java_process.sh and the above script, the ssh session did not terminate which I didn't know why. It just hanged there. I would like the ssh session to terminate when hitting exit 0 in that script.
2) When the java process somehow terminates, make sure the pid file is removed as well.
The link mentioned in the comment pretty much solved my problem.
linux shell ssh
linux shell ssh
edited Aug 31 at 9:29
asked Aug 31 at 4:54
du369
1012
1012
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh commandssh someuser@host /path/to/startup_java_process.shto terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.
â du369
Aug 31 at 5:08
1
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding<â¯/dev/nullon both lines where you are redirecting file descriptors 1 andâ¯2.
â G-Man
Aug 31 at 5:14
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
1
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13
 |Â
show 3 more comments
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh commandssh someuser@host /path/to/startup_java_process.shto terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.
â du369
Aug 31 at 5:08
1
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding<â¯/dev/nullon both lines where you are redirecting file descriptors 1 andâ¯2.
â G-Man
Aug 31 at 5:14
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
1
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh command
ssh someuser@host /path/to/startup_java_process.sh to terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.â du369
Aug 31 at 5:08
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh command
ssh someuser@host /path/to/startup_java_process.sh to terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.â du369
Aug 31 at 5:08
1
1
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding
<â¯/dev/null on both lines where you are redirecting file descriptors 1 andâ¯2.â G-Man
Aug 31 at 5:14
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding
<â¯/dev/null on both lines where you are redirecting file descriptors 1 andâ¯2.â G-Man
Aug 31 at 5:14
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
1
1
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13
 |Â
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f465918%2fhow-to-make-sure-the-pid-file-is-removed-when-the-corresponding-process-terminat%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
do you want java? and/or the startup_cleanup_pid in the background?
â danblack
Aug 31 at 5:00
@danblack No familiar with the background mechanism. So I will explain what I'm trying to do achieve. 1) I would like the ssh command
ssh someuser@host /path/to/startup_java_process.shto terminate, not hanging there. (I don't know why it does not terminate. I see the "about to exit" echo, but it just hangs.) 2) When the java process somehow terminates, make sure the pid file is removed as well.â du369
Aug 31 at 5:08
1
(1)â¯Please edit your post so the title and the body are asking the same question.âÂÂ(2)â¯Try adding
<â¯/dev/nullon both lines where you are redirecting file descriptors 1 andâ¯2.â G-Man
Aug 31 at 5:14
@G-Man I just tried it. But it doesn't seem to work.
â du369
Aug 31 at 5:29
1
stackoverflow.com/questions/14679178/â¦
â Ralph Rönnquist
Aug 31 at 6:13