1

I just wanted to make sure that I understand the foreground and background process. Let's say, I have a program Hello_world.

If I want to start the program I type in the foreground:

Hello_world

Then if I want to continue Hello_world in the background I type:

bg Hello_world

If I want to kill the job I type:

kill -9 %(job#) 

Also, how would I check to see if the job is terminated?

0

If you type:

jobs

It should tell you what status are your background jobs in.

See manual for further info.

Example:

./job &

Now it is running on background.

You can kill it by:

kill %1

or use any switch like:

-HUP

-TERM

-KILL

In any case in the end you would like to see:

[1]+  Terminated              ./job

And this is done again by jobs command.

0

Great explanation by @Vlastimil. I would add only that you can jump between foreground / background:

fg %background_job_ID

e.g.,

fg %2

and now you brought it to foreground, you are in that context, meaning that you can:

pause (stop/suspend): Ctrl+Z

interrupt:      Ctrl+C   (this will typically cause the process to terminate; i.e., exit)

During all of this you can see what is running, what is paused and what is terminated by executing the jobs command.

But yeah, that is kind of the main aspects of background / foreground via shell management.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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