Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
|
01-05-2010, 09:59 AM
|
#1
|
Member
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397
Rep:
|
Process / Job control.
I have a script which runs: -
e2fsck -p -v -c -f /dev/sdb1 > e2fsck_sdb.log &
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"?
Thanks for any help!
|
|
|
01-05-2010, 10:19 AM
|
#2
|
Member
Registered: Feb 2008
Location: Rome, Italy
Distribution: OpenSuSE 11.x, vectorlinux, slax, Sabayon
Posts: 206
Rep:
|
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.
|
|
|
01-05-2010, 10:23 AM
|
#3
|
Member
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208
Rep:
|
Why bring it to the foreground?
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.
|
|
|
01-05-2010, 10:50 AM
|
#4
|
Member
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397
Original Poster
Rep:
|
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?
E.G.
[root@joshua11 ~]# ps -elf | grep e2fsck
0 S root 1692 1 0 80 0 - 33038 pipe_w 16:39 ? 00:00:01 e2fsck -c -v -f /dev/sdb1
0 S root 1743 1704 0 80 0 - 25682 pipe_w 16:51 pts/1 00:00:00 grep e2fsck
[root@joshua11 ~]# fg 1692
-bash: fg: 1692: no such job
[root@joshua11 ~]#
Last edited by arashi256; 01-05-2010 at 10:52 AM.
|
|
|
01-05-2010, 11:17 AM
|
#5
|
Senior Member
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Rep:
|
Quote:
Originally Posted by arashi256
Must be a way around that, surely? Or is that what screen is for?
|
Yes, that is what screen is for. When you exit your shell, you lose access to your job list.
Quote:
Originally Posted by arashi256
[root@joshua11 ~]# fg 1692
-bash: fg: 1692: no such job
[root@joshua11 ~]#
|
A job number would normally be a small number. For example
Code:
[user@machine:~]:xterm &
[1] 8786
[user@machine:~]:
Here, the job number is "1". The PID is "8786". Normally, you would bring this job to the foreground using "fg %1".
For more information, run "man bash" and read the section titled "JOB CONTROL".
|
|
|
All times are GMT -5. The time now is 03:41 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|