Well it goes like this, I had to run a program from my home by ssh
ing into the server in my institution. I did not want my program to be terminated when the session closes(I didn't know about screen
).
What i did was press Ctrl+Z
and then type bg
so that it executes in the background. The session got terminated. Now when I login from my institution machine and type ps -u username
, it shows that the program is still running but I'm unable to bring it to foreground.
I tried fg
and jobs
but these commands don't give me any output.
Please someone help me..
Use Ctrl + Z to suspend a program then bg to run the process in background and disown to detach it from your current terminal session. With the built-in bash job call you can list all the existed backgrounded process, you can use fg to run the process in foreground again as long as it didn't get detached.
Use fg cmd to bring a background process to foreground.
Bringing a Background Job to the Foreground. We can reconnect a background job to our terminal with the Linux command fg. This command will bring job 2 into the foreground. If no job ID is given, fg will assume we're referring to the current (suspended) job.
If you have started the process without using "screen" command then you cannot take over that process. Basically you cannot take over a process that was started in a different shell.
When your session is terminated all the bg process will go the detached state. Though you might be able to see the details of such process you cannot fg them to a shell from login afterwards
If a process has been orphaned, you can't "reparent" it to a different shell and use fg, bg, ^Z, ^C, and so forth to control it.
It seems you're asking implicitly how to control an orphaned process. Since you can see the process using the ps command, you have its pid. You can use this pid as the argument to the kill command, which will allow you to stop, continue, or terminate the process. You can't wait for the process to finish, but you can poll to see whether it still exists by using the "kill -0 <pid>" command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With