Join Chaim Krause for an in-depth discussion in this video Work with background processes, part of SUSE Linux Enterprise Server Essential Training.
- [Instructor] So we've been working, so far, with the command line and talking about single processes that we're running, but we know very well that the computer is running multiple programs at the same time. Those services are running in the background, and they're being done automatically, controlled by systemd; and what we're going to do is show how to do this manually. Now there's another program that we can run called xterm, which will bring up a GUI terminal; and this is a terminal, and we can do things in there like we can, like doing an LS or doing a cat.
And it's independent of this terminal over here. But we can see that when we started up xterm, we sort of lost control of the terminal over here. That's because when we started xterm, it became the foreground process. Now what we can do is we can go back to our standard terminal here and we can issue Ctrl + Z. What that's gonna do is that's gonna take the process we started, stop it, and put it in the background.
So if we go back over to our xterm, I'm gonna enter in LS and enter here; there's no interactivity with it because it's in the background. If I come back to here and I bring it back to the foreground, now that LS executes. Ctrl + Z and it stopped again. Now what happens if I want both of them going at the same time? Well, I can see what's running by using jobs; and I can see we've got one job, and it is stopped.
So I'm gonna say, run in the background job number one; and now we've got both running at the same time, and they're not interfering with each other and I can open up another terminal. Now let's take a look at the output from when we said BG one. We got back exterm and then ampersand. What we can do is we can do that directly. So I'm gonna do xterm, space, ampersand; and look what happened.
We opened up a terminal, and it immediately went to the background. So if I do jobs over here, I can see that we've got these two jobs running. If I bring one back to the foreground, I just say which one I want to bring to the foreground. So let's bring two to the foreground, and now it's the foreground window, so if I do a Ctrl + C here, it's gonna terminate that terminal. I've got the other one running; I can just as easily terminate it from here.
Now if we look at what jobs we had running, we can see that that one is done. So the concept we have here is foreground and background. If you have a program in the foreground and you wanna move it into the background, you do a Ctrl + Z, that'll stop it; and then you can do a BG to have it run in the background. Xterm, rerun it, Ctrl + Z, in the original terminal background. If we don't issue a number it'll use the most recent one.
So you can see how this can come in handy if you need to open up another terminal window to look something up possibly using a man page while you still got the other terminal open. I've only touched upon the basics here. If you'd like more information, you can check out other videos in our library, like Linux, Multitasking at the Command Line.
- What is SUSE Linux Enterprise?
- Installing SLES
- Linux file types
- Working at the command line
- Managing processes
- Working with background processes
- Managing users and groups
- Changing file permissions
- Configuring network interfaces
- Displaying hardware information
- Managing drivers