Basic Job Management

From LinuxReviews
Jump to navigationJump to search

If you are in a terminal console you can run commands and wait for them to finish. But you don't have to. If you want to launch a browser and keep on using the terminal you can start it as a "background" job by adding & to the command. Exapmle:

konqueror &

will start konqueror in the background. What if you forget & and want to put it in the background later? You can press ctrl-z to "stop" the "job" (in this case Konqueror). You will now get message saying [2]+ Stopped konqueror. That means Konqeruror is job #2 and it's stopped.

You can make that job a background job by typing bg 2 and put it back in the foreground with fg 2. You can just use bg or fg if there's just one job.

Now, if you run a program and press ctrl-Z - stopping that job - and you keep on using the terminal and forget about it and try to close the terminal with exit or ctrl-d you will get a message saying There are stopped jobs.. If that's the case you can just type fg and bring the job to the foreground. You can then terminate it by pressing ctrl-c.

The command jobs will list all the jobs you have running. Adding -l will list the PID (Process ID) of the various jobs. Thus, you can run jobs -l and then use kill PID to eradicate one of the jobs you have running. Adding -r will list only running jobs, -s will only list stopped jobs.


Questions?


avatar

Anonymous (40f2754ff0)

23 months ago
Score 0
what's the precise difference between fg job and bg job?
avatar

Anonymous (4077031fad)

13 months ago
Score 0

> Anonymous (40f2754ff0)

> what's the precise difference between fg job and bg job?

Good question, author show here usage, but didn't explain the differnce.

If simple: fg — run jobs in the foreground so it takes(capture) tty(terminal). bg — run jobs in the background, so it "detached" program from tty(terminal), so program don't paused(suspended) and just work in background, if you want back background program to tty(terminal) you can use fg to take it back.

When you press ^Z (ctrl-z) you pause(suspend) current program so you can continue use terminal, when you need back to program or you want that program continue to work in background you use fg or bg. But before fg\bg this program just on pause (suspend).
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.