Viewers: in countries Watching now:
Unix for Mac OS X Users unlocks the powerful capabilities of Unix that underlie Mac OS X, teaching how to use command-line syntax to perform common tasks such as file management, data entry, and text manipulation. The course teaches Unix from the ground up, starting with the basics of the command line and graduating to powerful, advanced tools like grep, sed, and xargs. The course shows how to enter commands in Terminal to create, move, copy, and delete files and folders; change file ownership and permissions; view and stop command and application processes; find and edit data within files; and use command-line shortcuts to speed up workflow. Exercise files accompany the course.
Over the course of the last two movies we've been looking at how we can view and monitor the different processes that are running in Unix. In this movie I want us to see how we can stop processes. Now, the number one best way to stop a process is with Ctrl+C. That assumes that you're running the process inside your Terminal window. You started it. It's just taking too long or maybe you changed your mind in the middle of it. Ctrl+C tells Unix, hey! Stop that process, interrupt it, let's go back to the command line. So that's the best thing, but sometimes we can't use that. Sometimes there are processes that are running in the background, or maybe there's a process that we did have control of but somehow we've lost control.
So we can still see it, we can see it's running there, and we really wish it would go away. Well, to do that, we use the kill command. In order to show you how we would do it, let's do ps aux. We see a listing there and you will see I have a listing on here for s000 bash. That's my current bash program. Now I am going to open up a new window. Essentially what I want here is a process that I am not afraid to kill off, because I don't have an errant process running right now and I don't want to use sort of advanced tricks to get one running. Instead, I am just going to create this new Terminal here.
Now when I do ps aux you'll see that I see another bash here and this bash is owned by 0001. Let's clear the screen just so we can see it nice and well. Here is bash down here and if we scroll up here, it should be this other bash up here. Now notice 000 is the one that I am on. That's the one I don't want to get rid of. The one I want to get rid of is 001. That's the other window that's going on and that's the process I am going to kill. I am going to forcibly just stop that bash from running.
What I need is the process ID. That's how we tell Unix which process we want. Every single process has a unique ID, so it's the way that we can reference it. What we use is kill 1837. That's the process ID. We have killed it, except that we haven't. Some processes can't be killed by using kill on its own like this. So always try kill first. It'll do its best to kill it off. But there are cases where it'll say, you know what, I think you probably don't want to do that. This is one of those cases, because it's running bash in a Terminal window.
So it says, you know what, I could kill that off but I think that's probably not a great idea. So it didn't do it. Let's just take a look here. ps aux, I will clear the screen, just so we can see it is still running. Right here it is 001, bash, same process ID. But if we pass it the -9 option, that says, yeah! I know better than you. It means really, really, really kill this thing off. Forcibly kill it. So kill -9 and then the process ID number. Now, I killed it off. Let's take ps aux again. Take a look.
Notice that it's not there. The only bash that I have is 000 and come over here to the other Terminal and look, process completed. The process is done. If I hit anything, I don't get anything in that window anymore. I killed off that process. But you can do this anytime you've got a process that's taking up tons of memory, tons of CPU usage, something you don't have control over. Obviously you want to be careful. A lot of these processes your system needs. You don't want to just start killing off processes willy-nilly. But it is a technique if there is a process that you know needs to be killed. This is how you would do it.
First, try kill and then kill with the - 9 option as well.
Find answers to the most frequently asked questions about Unix for Mac OS X Users .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.