Linux Process Management

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lesson we're going to discuss managing running Linux processes specifically we're going to look at running processes in the background and also switching processes between the background and the foreground so let's start by talking about how you run processes in the background recall that whenever you run any command at the shell prompt on a Linux system a new sub shell process is created and then that process that you wanted to run is run within that sub shell and as soon as that process exits then it's associated sub shell is destroyed as well here's the key thing that you need to remember during the time that that process remains running the shell prompt of the parent shell itself disappears and you can't do anything at the shell prompt unless you were to open up a new terminal session this happens because the process is running in what's called the foreground now this behavior is even more apparent when you run a graphical application from the shell prompt in this example I've used the libera office command to launch the LibreOffice application notice that while libera office is running over here the shell prompt is unavailable and it's going to remain that way until I close this window by clicking on that X right there or clicking file exit over here only then can I enter additional commands at the shell prompt if I need it to enter another command without closing the libera office application I would have to open up a new terminal window over here and enter those commands there now this is the default behavior for any command that you enter at the shell prompt and it doesn't matter whether that command runs a text-based shell program or whether it runs a graphical program the effect is the same but be aware that it is possible to run the program not in the foreground but in the background instead if you do this the program you launch will run normally but control will be returned immediately to the shell session where you ran the command and then you can use the shell to launch other programs or to perform other tasks and the process for doing this is really quite easy it's not that difficult to run a program in the background in this example I've run the same application that I ran in the previous example I entered libera office at the shell prompt but notice that I added one character at the end of the command I added a space and then I appended an ampersand character to the command this is very important this ampersand character tells the shell to run the program not in the foreground but the two instead run it in the background by doing this I still have the same application window graphical application window that I had before but I get my shell prompt back now notice that when I ran this command with the ampersand that two values were displayed on the screen once the process was loaded into the background the first value right here is the job ID and the second value is the process ID of the process being run to create this application now this job ID number is very important because it helps you keep track of all of your background jobs in fact you can view a list of all the background jobs currently running on the system by entering just the simple jobs command at the shell prompted as you can see in this example I have just one background job running it's job ID is one its status is running and here's the name of the command that I use to create that background job now just because a process was loaded into the background or to the foreground for that matter doesn't mean that it has to stay there you can actually switch a process between the foreground and the background while it's still running now what do you do if you have a process that's currently running in the foreground and you decide wait a minute I actually want that running in the background well one option would be to close the application and then load it again using the command that we just looked at by appending an ampersand to the end of the command that is one way to do it however there is another and I think better way to do this just because a process was started in the background or in the foreground it doesn't matter doesn't mean it has to actually stay there without stopping you actually switch a process between the foreground and the background while leaving it running and this is done using the two shell commands shown here the first one is the FG command this command will move a background process to the foreground now in order to use the FG command you do have to know the job ID number of that process that you want to move from the background to the foreground use the jobs command to find out what that is if you don't already know it once you do you just type FG and then the job ID number and the process jumps from the background into the foreground you can do just the opposite with the BG command as its name implies this command will take a process that's running in the foreground and move it into the background now before you can do this you do have to assign the foreground job a job ID number because remember when we loaded a process directly into the background it was assigned a job ID number by default if we have a foreground job we've got to assign it one of those numbers before we can move it into the background and you do this by pressing the control Z key sequence when you do this you'll see the process stopped and a new job ID number will be assigned to that process once that's done all you have to do is type BG followed by the job ID number that was just assigned and it will move that process from the foreground to the background and it'll continue running an example of how to do that is shown here in this example I ran the VI editor to edit the zombie file now notice that I did not include an ampersand right here therefore this process the VI process ran in the foreground and then I decided to wait a minute I don't want to running in the foreground I want it running in the background so I pressed ctrl Z and when I do a job ID number was assigned and the process was temporarily stopped here's the name of the command that was used to start the original process and then I typed the BG command followed by the job number which moved the process into the background and it started running again that's it for this lesson in this lesson we talked about managing running Linux processes we first talked about how to the process in the background and then we looked at how you can move a process that's already running in the foreground to the background
Info
Channel: The Linux Man
Views: 3,033
Rating: 4.9569893 out of 5
Keywords: Linux
Id: mEJOGF-E8zg
Channel Id: undefined
Length: 6min 45sec (405 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.