LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



Reply
 
Search this Thread
Old 04-16-2010, 06:55 AM   #1
IanVaughan
Member
 
Registered: Jun 2009
Location: Brighton, UK
Posts: 49

Rep: Reputation: 16
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?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-16-2010, 06:58 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Bangalore, India
Distribution: Linux Mint 13
Posts: 592

Rep: Reputation: 64
Quote:
Originally Posted by IanVaughan View Post
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:

Quote:
#fg job_id
 
2 members found this post helpful.
Old 04-16-2010, 07:06 AM   #3
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,019

Rep: Reputation: 63
Quote:
Originally Posted by IanVaughan View Post
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?
Code:
man jobs
jobs command will display the background process.Then fg <number>
 
1 members found this post helpful.
Old 04-16-2010, 07:17 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by cola View Post
...
Then fg <number>
AFAIR it's

Code:
fg %JOB_NUMBER
- 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
.
 
Old 04-16-2010, 07:37 AM   #5
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,019

Rep: Reputation: 63
Quote:
Originally Posted by Sergei Steshenko View Post
AFAIR it's

Code:
fg %JOB_NUMBER
- 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.
Old 04-16-2010, 08:09 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by cola View Post
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.
Old 04-16-2010, 08:15 AM   #7
IanVaughan
Member
 
Registered: Jun 2009
Location: Brighton, UK
Posts: 49

Original Poster
Rep: Reputation: 16
Can you not post crap thats not related to this topic please!

Anyway, jobs returns nothing for me!

Cheers.
 
Old 04-16-2010, 08:19 AM   #8
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,019

Rep: Reputation: 63
Quote:
Originally Posted by IanVaughan View Post
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.
 
Old 04-16-2010, 08:22 AM   #9
IanVaughan
Member
 
Registered: Jun 2009
Location: Brighton, UK
Posts: 49

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by cola View Post
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!?
 
Old 04-16-2010, 08:22 AM   #10
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
What actually this does?

have you tried this on a shell ?

Code:
( sleep 20000000 | fp ) &
do something like

Code:
(sleep 10 | ps ) &
What goes in to background ?


Hope it gives you a pointer.

I personally did not like the word crap for normal discussion
 
Old 04-16-2010, 08:29 AM   #11
cola
Senior Member
 
Registered: Sep 2007
Location: Dhaka,Bangladesh
Distribution: Debian
Posts: 1,019

Rep: Reputation: 63
Quote:
Originally Posted by IanVaughan View Post
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 &
 
Old 04-16-2010, 08:34 AM   #12
IanVaughan
Member
 
Registered: Jun 2009
Location: Brighton, UK
Posts: 49

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by PMP View Post
What actually this does?

have you tried this on a shell ?

Code:
( sleep 20000000 | fp ) &
do something like

Code:
(sleep 10 | ps ) &
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
Code:
fg 1
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!
 
Old 04-16-2010, 08:43 AM   #13
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
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.
 
Old 04-16-2010, 09:26 AM   #14
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by IanVaughan View Post
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
Code:
fg 1
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
Code:
fg %1
To put it in the background you need to
Code:
bg %1

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 09:37 AM. Reason: more clarification
 
  


Reply

Tags
bg, fg, job, pid


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
all cron job details with any single command mayrus9 Suse/Novell 3 04-01-2010 04:31 AM
Job resumed in background still outputs to stdout in foreground lumix Linux - Newbie 3 11-28-2008 09:05 PM
cron job and boot command Thulemanden DamnSmallLinux 3 11-08-2006 01:22 AM
Cron Job help...how to write this command? pxumsgdxpcvjm Linux - Newbie 2 09-05-2006 05:42 AM
trying to run job with at command mnauta Linux - Networking 1 03-10-2005 05:13 AM


All times are GMT -5. The time now is 11:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration