Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
04-16-2010, 05:55 AM
#1
Member
Registered: Jun 2009
Location: Brighton, UK
Posts: 50
Rep:
how to use fg foreground command? no such job!
I have many processes running that printf local debug. (they will log to file later!)
I start them by
Code:
( sleep 20000000 | fp ) &
else they get killed/stop by themselves.
So now its running in the background, I want to bring it to the front to see the printfs.
Code:
# pgrep fp
3301
# fg 3301
-bash: fg: 3301: no such job
Why no such job?!
How do I use it?
man fg
Quote:
fg [jobspec]
Resume jobspec in the foreground, and make it the cur-
rent job. If jobspec is not present, the shellâs
notion of the current job is used. The return value
is that of the command placed into the foreground, or
failure if run when job control is disabled or, when
run with job control enabled, if jobspec does not
specify a valid job or jobspec specifies a job that
was started without job control.
What is jobspec?
04-16-2010, 05:58 AM
#2
Member
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 624
Rep:
Quote:
Originally Posted by
IanVaughan
I have many processes running that printf local debug. (they will log to file later!)
I start them by
Code:
( sleep 20000000 | fp ) &
else they get killed/stop by themselves.
So now its running in the background, I want to bring it to the front to see the printfs.
Code:
# pgrep fp
3301
# fg 3301
-bash: fg: 3301: no such job
Why no such job?!
How do I use it?
man fg
What is jobspec?
First run the command
jobs to know the job id which is different from the process id.
Then use fg to bring it in foreground:
2 members found this post helpful.
04-16-2010, 06:06 AM
#3
Senior Member
Registered: Sep 2007
Posts: 1,045
Rep:
Quote:
Originally Posted by
IanVaughan
I have many processes running that printf local debug. (they will log to file later!)
I start them by
Code:
( sleep 20000000 | fp ) &
else they get killed/stop by themselves.
So now its running in the background, I want to bring it to the front to see the printfs.
Code:
# pgrep fp
3301
# fg 3301
-bash: fg: 3301: no such job
Why no such job?!
How do I use it?
man fg
What is jobspec?
jobs command will display the background process.Then fg <number>
1 members found this post helpful.
04-16-2010, 06:17 AM
#4
Senior Member
Registered: May 2005
Posts: 4,481
Quote:
Originally Posted by
cola
...
Then fg <number>
AFAIR it's
- at least, this is how it works for me.
A job can also be put into foreground based on its PID using 'kill' with the appropriate signal - see
Code:
man kill
man 7 signal
.
04-16-2010, 06:37 AM
#5
Senior Member
Registered: Sep 2007
Posts: 1,045
Rep:
Quote:
Originally Posted by
Sergei Steshenko
AFAIR it's
- at least, this is how it works for me.
A job can also be put into foreground based on its PID using 'kill' with the appropriate signal - see
Code:
man kill
man 7 signal
.
Code:
If Python don't have unless construct, it means it doesn't need one. (c) ghostdog74
Why is this?
0 members found this post helpful.
04-16-2010, 07:09 AM
#6
Senior Member
Registered: May 2005
Posts: 4,481
Quote:
Originally Posted by
cola
Code:
If Python don't have unless construct, it means it doesn't need one. (c) ghostdog74
Why is this?
I quoted
ghostdog74 - ask him
. Perl does have 'unless' construct, and I like it.
0 members found this post helpful.
04-16-2010, 07:15 AM
#7
Member
Registered: Jun 2009
Location: Brighton, UK
Posts: 50
Original Poster
Rep:
Can you not post crap thats not related to this topic please!
Anyway, jobs returns nothing for me!
Cheers.
04-16-2010, 07:19 AM
#8
Senior Member
Registered: Sep 2007
Posts: 1,045
Rep:
Quote:
Originally Posted by
IanVaughan
Can you not post crap thats not related to this topic please!
Anyway, jobs returns nothing for me!
Cheers.
If jobs does not return anything then there is no background process.
04-16-2010, 07:22 AM
#9
Member
Registered: Jun 2009
Location: Brighton, UK
Posts: 50
Original Poster
Rep:
Quote:
Originally Posted by
cola
If jobs does not return anything then there is no background process.
Interesting!
But I have many processes running, are they actually not all background processes, or just processes then?
What I may be after then is to be able to switch to another process that is running!?
04-16-2010, 07:22 AM
#10
Member
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381
Rep:
What actually this does?
have you tried this on a shell ?
Code:
( sleep 20000000 | fp ) &
do something like
What goes in to background ?
Hope it gives you a pointer.
I personally did not like the word crap for normal discussion
04-16-2010, 07:29 AM
#11
Senior Member
Registered: Sep 2007
Posts: 1,045
Rep:
Quote:
Originally Posted by
IanVaughan
Interesting!
But I have many processes running, are they actually not all background processes, or just processes then?
What I may be after then is to be able to switch to another process that is running!?
If you use "&" at the end of a command,then you get a background command.
Example:
Code:
mplayer file1.flv &
04-16-2010, 07:34 AM
#12
Member
Registered: Jun 2009
Location: Brighton, UK
Posts: 50
Original Poster
Rep:
Quote:
Originally Posted by
PMP
What actually this does?
have you tried this on a shell ?
Code:
( sleep 20000000 | fp ) &
do something like
What goes in to background ?
Ok, my mistake, I had killed my "fp" background process!
When started (as quoted above) jobs gives me :-
Code:
[1]+ Running ( sleep 20000000 | fp ) &
so, typing in
should bring it to the front, right? I cant prove it right now, but will post back when I can.
And once in the fg, how can I push it back to the bg again?
thanks for bearing with me!
04-16-2010, 07:43 AM
#13
Member
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381
Rep:
Yes your process fp is running at that time.
My question was it in background ?
pgrep will give you the processid, no matter it is in forground or background.
Have you tried what I said
Code:
(sleep 1000 | ps ) &
after doing so you will receive
-bash-3.2$ (sleep 1000 | ps) &
[
5 ]
30766
Job Number ,
Processid
no if you do
fg 5 ie fg [job_number] you will se your job in background.
04-16-2010, 08:26 AM
#14
Member
Registered: Nov 2005
Distribution: Raspbian, Debian, Ubuntu
Posts: 380
Rep:
Quote:
Originally Posted by
IanVaughan
Ok, my mistake, I had killed my "fp" background process!
When started (as quoted above) jobs gives me :-
Code:
[1]+ Running ( sleep 20000000 | fp ) &
so, typing in
should bring it to the front, right? I cant prove it right now, but will post back when I can.
And once in the fg, how can I push it back to the bg again?
thanks for bearing with me!
To bring it to the foreground you need to
To put it in the background you need to
e.g.
Code:
[root@athlonz ~]# ( sleep 20000000 | cat /etc/*ease ) &
[1] 31071
[root@athlonz ~]# Fedora release 10 (Cambridge)
Fedora release 10 (Cambridge)
Fedora release 10 (Cambridge)
[root@athlonz ~]# jobs
[1]+ Running ( sleep 20000000 | cat /etc/*ease ) &
[root@athlonz ~]# ( sleep 20000000 | cat /etc/fstab ) &
[2] 31120
[root@athlonz ~]#
#
# /etc/fstab
# Created by anaconda on Mon Feb 15 02:00:36 2010
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or vol_id(8) for more info
#
UUID=54716048-c91b-4f48-b37e-fb09ce21e412 / ext3 defaults 1 1
UUID=1fd8498a-868b-46b6-8ced-01155b0c5962 /bkup ext3 defaults 1 2
UUID=97bcf411-5558-4cf9-9aef-5108fa686246 /boot ext3 defaults 1 2
UUID=59d3649f-4c9d-46b2-94c8-b7d29578328e /boot2 ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
UUID=b827e20f-db5b-47b2-be38-17489895a0ad swap swap defaults 0 0
/dev/mapper/vgz01-tommy /home/tommy ext3 defaults 1 2
[root@athlonz ~]# jobs
[1]- Running ( sleep 20000000 | cat /etc/*ease ) &
[2]+ Running ( sleep 20000000 | cat /etc/fstab ) &
[root@athlonz ~]# fg %1
( sleep 20000000 | cat /etc/*ease )
^Z
[1]+ Stopped ( sleep 20000000 | cat /etc/*ease )
[root@athlonz ~]# jobs
[1]+ Stopped ( sleep 20000000 | cat /etc/*ease )
[2]- Running ( sleep 20000000 | cat /etc/fstab ) &
[root@athlonz ~]# bg %1
[1]+ ( sleep 20000000 | cat /etc/*ease ) &
[root@athlonz ~]# jobs
[1]- Running ( sleep 20000000 | cat /etc/*ease ) &
[2]+ Running ( sleep 20000000 | cat /etc/fstab ) &
[root@athlonz ~]# kill %1
[root@athlonz ~]# jobs
[1]- Terminated ( sleep 20000000 | cat /etc/*ease )
[2]+ Running ( sleep 20000000 | cat /etc/fstab ) &
[root@athlonz ~]#
[root@athlonz ~]# jobs
[2]+ Running ( sleep 20000000 | cat /etc/fstab ) &
[root@athlonz ~]# kill %2
[root@athlonz ~]#
[2]+ Terminated ( sleep 20000000 | cat /etc/fstab )
[root@athlonz ~]#
[root@athlonz ~]# jobs
[root@athlonz ~]#
Last edited by tommylovell; 04-16-2010 at 08:37 AM .
Reason: more clarification
11-02-2016, 03:49 AM
#15
LQ Newbie
Registered: Nov 2016
Posts: 1
Rep:
jobs vs processes
There seems to be an important distinction between "jobs" in the current shell and "processes" in the session. "ps" and "kill" can be used to look at and chnage the states of processes in the session (e.g. "kill -CONT $PID" to bring a suspended process back to life). "jobs" and "fg" can only be used for jobs in the current shell.
All times are GMT -5. The time now is 01:10 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