Linux forum

General discussion

Linux PID from background to foreground

Hey guys.

I'm running Debian Linux and I have a question with PIDs.

When I do "pgrep (name)" I get a PID.

But, the PID is running background and I want to make it go in the foreground. I'm using 100% textbased terminal/console, so I'm wondering how to do that... Since I don't have the GUI. What are the commands?

Thanks Happy

Discussion is locked
You are posting a reply to: Linux PID from background to foreground
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: Linux PID from background to foreground
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
System and user.

In reply to: Linux PID from background to foreground

Can you start X as user?
Anyway. Is it system or user?
System needs to be edited with sysvinit or the user needs to be added to the group.
You can also try top.
Use bg and fg.

Collapse -
Yea

In reply to: System and user.

I could start X as a user but my account is admin in visudo.

I've tried doing bg and fg but when I type "jobs" it doesn't list any jobs.

When I do top I can get a whole list of unorganized process PIDs.. so instead I just do "pgrep (program)"

Any input?

Collapse -
GUI and console

In reply to: Yea

Try the forums for your distro, linuxquestions, or the debian forums for the answer if this doesn't work, k?
KDE -> System -> Kguard. Look at process ID on list.
Open a console on a separate desktop.
Su to root.

Use fg or bg to move the processes.

Collapse -
Doesn't fg and bg only move the Jobs?

In reply to: GUI and console

Not the PID?

Yea. I've been going through Google for the past 3 days with still no luck Silly

Collapse -
Forums

In reply to: Doesn't fg and bg only move the Jobs?

Did you ask at the forums?

Collapse -
Nope

In reply to: Forums

I don't have an account and don't feel like making one haha.
I went through the Ubuntu and Debian forums.. With no luck

Collapse -
Forum help

In reply to: Nope

I'm in the debian forums. Do you want me to ask for you?

Collapse -
:)

In reply to: Forum help

If it's not a problem, please.

Like, I've been around and checked and they always say "type jobs then bg, fg" or whatever. But when I type "jobs" nothing happens haha.

Collapse -
Heh

In reply to: Jobs PID

Haha, when I type jobs it won't show me anything.
I think jobs are different from PID. xD

Collapse -
Jobs and PID

In reply to: Heh

You need to use them together. Did you use pgrep along with user and group flags?

Collapse -
I don't think so

In reply to: Jobs and PID

I host a ventrilo so I just do "pgrep ventrilo" and it gives me 4 numbers. My account is in the /etc/sudoers as admin ALL=(ALL) ALL.

Collapse -
Use the pgrep output

In reply to: Linux PID from background to foreground

If the Pgrep output gives you four numbers then the job number you want should be under that process. Are you trying to move a child process into the foreground or a parent?

I'll try another forum to see if there is any other help I can route you to.
Hold on, k?

Collapse -
Heh...

In reply to: Use the pgrep output

Yea. pgrep = 4 numbers. Except they won't do anything with bg or fg.

Basically, since I use SSH to connect to my machine, I want to pop open the server (since it's terminal based) from the PID.

It doesn't matter anymore haha. You can can stop helping. I just went back to the GUI, and for SSH I just do random stuff that isn't server related. Silly

Thanks for your help though.

Collapse -
Aiiiight

In reply to: Use the pgrep output

Whatever. It doesn't matter anymore. I went back to using full-out GUI on a live distribution. Works like a Charm. Why ignore a GUI when you have one available Silly

Collapse -
The solution.

In reply to: Linux PID from background to foreground

Stop giving up .

http://linuxfrombeginning.wordpress.com/2008/09/29/linux-command-13-jobs-bg-fg-top/

And here is my output from the example.


.

moleque@debian:~$ jobs -s
moleque@debian:~$ jobs -p
moleque@debian:~$ sleep 100
^Z
[1]+ Stopped sleep 100
moleque@debian:~$ bg
[1]+ sleep 100 &
moleque@debian:~$ sleep 150
^Z
[2]+ Stopped sleep 150
moleque@debian:~$ sleep 130
^Z
[3]+ Stopped sleep 130
moleque@debian:~$
moleque@debian:~$ top

top - 20:29:55 up 5:50, 2 users, load average: 0.54, 0.47, 0.34
Tasks: 111 total, 1 running, 108 sleeping, 2 stopped, 0 zombie
Cpu(s): 18.4%us, 4.6%sy, 0.0%ni, 74.6%id, 0.7%wa, 0.2%hi, 1.5%si, 0.0%st
Mem: 1736916k total, 1258072k used, 478844k free, 95828k buffers
Swap: 779112k total, 0k used, 779112k free, 805204k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9072 nobody 20 0 13260 1876 612 S 33.3 0.1 9:17.92 tcpspy
6044 root 20 0 208m 78m 5448 S 3.9 4.6 5:02.02 Xorg
7485 moleque 20 0 437m 41m 18m S 3.9 2.4 0:21.30 deluge
7501 moleque 20 0 18820 1168 856 R 3.9 0.1 0:00.02 top
1 root 20 0 10312 744 616 S 0.0 0.0 0:00.96 init
2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 15 -5 0 0 0 S 0.0 0.0 0:00.98 ksoftirqd/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
6 root 15 -5 0 0 0 S 0.0 0.0 0:00.78 events/0
7 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khelper
41 root 15 -5 0 0 0 S 0.0 0.0 0:00.72 kblockd/0
43 root 15 -5 0 0 0 S 0.0 0.0 0:08.12 kacpid
44 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kacpi_notify
119 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 ksuspend_usbd
125 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khubd
128 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kseriod

[4]+ Stopped top
moleque@debian:~$ jobs
[1] Running sleep 100 &
[2] Stopped sleep 150
[3]- Stopped sleep 130
[4]+ Stopped top
moleque@debian:~$ bg 4 fg 2
[4]+ top &
bash: bg: fg: no such job
[2]- sleep 150 &

moleque@debian:~$ jobs
[1] Running sleep 100 &
[2] Running sleep 150 &
[3]- Stopped sleep 130
[4]+ Stopped top
moleque@debian:~$ fg 4
top


top - 20:30:45 up 5:50, 2 users, load average: 0.42, 0.45, 0.34
Tasks: 111 total, 2 running, 108 sleeping, 1 stopped, 0 zombie
Cpu(s): 3.7%us, 12.0%sy, 0.0%ni, 70.0%id, 2.3%wa, 1.3%hi, 10.7%si, 0.0%st
Mem: 1736916k total, 1296268k used, 440648k free, 95996k buffers
Swap: 779112k total, 0k used, 779112k free, 842236k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
9072 nobody 20 0 13260 1876 612 R 17.0 0.1 9:25.13 tcpspy
7485 moleque 20 0 437m 41m 18m S 7.0 2.4 0:24.45 deluge
43 root 15 -5 0 0 0 S 2.0 0.0 0:09.20 kacpid
908 root 15 -5 0 0 0 S 0.7 0.0 0:06.04 kjournald
6044 root 20 0 208m 78m 5448 S 0.7 4.6 5:02.40 Xorg
7501 moleque 20 0 18824 1256 940 R 0.7 0.1 0:00.04 top
1 root 20 0 10312 744 616 S 0.0 0.0 0:00.96 init
2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 15 -5 0 0 0 S 0.0 0.0 0:00.98 ksoftirqd/0
5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0
6 root 15 -5 0 0 0 S 0.0 0.0 0:00.78 events/0
7 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khelper
41 root 15 -5 0 0 0 S 0.0 0.0 0:00.72 kblockd/0
44 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kacpi_notify
119 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 ksuspend_usbd
125 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khubd
moleque@debian:~$ jobs -s
[3]+ Stopped sleep 130
[1] Done sleep 100
moleque@debian:~$

Collapse -
Ahhhhh

In reply to: The solution.

I tried jobs and their -s and etc, and it didn't show anything.

the most important thing really is being able to stop and run the server, which I'm able to do.

Collapse -
BSD jails

In reply to: Ahhhhh

Have you tried running the server from within a sandbox?

Collapse -
Nope

In reply to: BSD jails

What is sandbox?

Collapse -
chroot

In reply to: Nope

A self contained environment that shares the kernel/system calls but is separated from affecting other processes. Do a search for "jail" and "chroot" in synaptic.
You can also build the server within a virtual environment and not let it have access to any file or device.

Collapse -
Interesting

In reply to: chroot

I'll do that when I have time Silly

Popular Forums

icon
Computer Newbies 10,686 discussions
icon
Computer Help 54,365 discussions
icon
Laptops 21,181 discussions
icon
Networking & Wireless 16,313 discussions
icon
Phones 17,137 discussions
icon
Security 31,287 discussions
icon
TVs & Home Theaters 22,101 discussions
icon
Windows 7 8,164 discussions
icon
Windows 10 2,657 discussions

SMART HOME

This one tip will help you sleep better tonight

A few seconds are all you need to get a better night's rest.