Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I was in the office using my desktop, I started a script in background 4 times. parameter1 & parameter2 & parameter3 & parameter4 &

Then I came home, and opened a terminal on my laptop, ssh to the desktop in my office. When ran ps -u jack, I saw the started processes:

 3562 pts/1    00:00:00 bash
 4540 pts/2    00:00:00 bash
 4643 pts/3    00:00:00 bash
 4748 pts/4    00:00:00 bash

But when I typed jobs, I got nothing. Why I could see these four running background processes?

Btw, how can I bring them back to my current terminal, so that I can kill one of them, say parameter4 &?

share|improve this question

migrated from Jun 13 '13 at 15:08

This question came from our site for professional and enthusiast programmers.

Where did you started the script, in a remote machine? – fedorqui Jun 13 '13 at 12:17
@fedorqui No the script was started on my desktop directly. – JackWM Jun 13 '13 at 12:18
Did you run jobs command in the same shell? – Grzegorz Jun 13 '13 at 12:20
@Grzegorz No, I opened a new one from my laptop. – JackWM Jun 13 '13 at 12:22
up vote 3 down vote accepted

Based on the problem statement of the question, IMHO I do not see any reason for using background or foreground. All you care is to find a process which is running in background so that you can kill it.

Run ps -ef | grep parameter3 to find processes which has parameter3 in the process name. You can adapt the grep to uniquely identify a process, given you don't have two processes with exactly same process name.

Once you have it, just do kill -9 PID and that process will be killed. So no need for bringing that process to the foreground for killing it.

Hope this helps.

share|improve this answer
I saw this jack 15766 3562 0 Jun12 pts/1 00:00:00 /bin/bash ./ 015d4a826e43f416 which number is the pid? – JackWM Jun 13 '13 at 12:44
@JackVW the second column is the PID. So you will do kill -9 15766. If you care, the third column is PPID (PID of the parent process). – Bill Jun 13 '13 at 12:45
Why kill -9? It's almost always better to start by using kill without the signal parameter first. That way, the killed process can tidy up before terminating if it has been programmed that way. Then if the process still refuses to die, you can use kill -9. – Adrian Pronk Jun 16 '13 at 11:06

This is because jobs shows background commands started from (belonging to) the same shell. The shell processes running under your desktop terminal and under ssh terminal are different.


To be able to control your processes as jobs from different terminals you can use screen or tmux which are basically virtual terminal managers and can re-connect them to any number of other terminals.

For example, with screen you just start it, it opens your default shell and you work with it as you would with any other shell. Then when you get home and ssh to your office machine, you can run screen -d -r to detach the virtual terminal from your office desktop terminal and attach it to your ssh terminal, resuming the work. You can detach the virtual terminal from within screen itself by pressing Ctrl-A, d.

share|improve this answer
Thanks for the info, then how can I bring them back to my current terminal? – JackWM Jun 13 '13 at 12:23
If you wish to run things "in the background", so to speak, and resume them later then something like GNU Screen or tmux would be useful. This will allow your to resume from any subsequent shell sessions whereas, as described above, you can only bring background jobs to the foreground from the same shell. – Fred Clausen Jun 13 '13 at 12:24
@JackWM use fg – Bill Jun 13 '13 at 12:24
@Bill Does fg require a background process number, which I don't have? – JackWM Jun 13 '13 at 12:26
@JackWM you can distinguish them using parameter3. run ps -ef | grep parameter3 and this will give you the pid of a process which contains parameter3. You can adapt this to your need. I tend to keep things as simple as possible. If all you need is to identify a pid for killing it, I really do not see any need for bg and fg, making life complicated :) – Bill Jun 13 '13 at 12:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.