Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
However, although this runs successfully in the background, I'd like to be able to log off and return later, pull it to the foreground and see how it's doing. When running this, I don't get a job number - it simply returns to the prompt - and using "jobs" returns nothing, although I can see it running by using "ps". I assume this has somehow got divorced from the shell session, so I am unable to use "fg" to bring it back to foreground.
Since I can get the Process ID very easily, is there a way to pull a process to the foreground from it's PID rather than it's job number? Or can I somehow get the correct job number from the PID in order to use "fg"?
Use the command "screen", that can "emulate" terminals on your host.
Basic usage: run "screen", then run your program without the '&'.
Then, use C-a C-d to "detach" the screen session. When you want to reattach to it, run "screen -R". Look at the man page, "screen" is a very flexible command.
All the output is being sent to a file. So, do a "cat" on the output file. If you want to watch the output as it goes, you could do "tail -f" on the file. I don't know of a way to bring back a process to the foreground with a PID, so this is the best I can come up with. Or, you could "screen" the command. That way, you can use a "screen -r" to recover the session.
Screen looks interesting - I'll get to that. However, the main problem seems to be (with any background job, it seems) that once you've logged out and log back in again, you've lost your shell association and although ps shows the process, you can no longer get to it with fg or jobs. Must be a way around that, surely? Or is that what screen is for?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.