Join Chaim Krause for an in-depth discussion in this video Manage processes, part of SUSE Linux Enterprise Server Essential Training.
- [Instructor] We've been talking about running commands and configuring things. Eventually we want something to actually happen, and when things are running, we wanna see what is running. So, there is a command that we're going to use, ps, which will show you the processes that are running in your session, with their program ID and a command that was used to start them. Now, if we look at the man page, or ps, we're gonna bring up the first one.
We see that we get a snapshot and that we can use different kinds of options, so if you're familiar with Unix or BSD (mumbling), those are all supported. Down at the bottom here it says, note that ps -aux is distinct from ps aux. These two things combined, this fact that there's all these different versions of options and arguments you can use and the fact that simply adding a dash or not having a dash is gonna make a big change, at least, in my opinion, makes ps a little confusing to use.
I an constantly having to look at the man page to figure out what it is that I need to see. If you don't grasp ps right away, don't panic. As long as you've got the man page there, you'll be just fine. There's a lot of things you can do to change formatting. It almost becomes a mini query language. So, if you've ever done anything like SQL, this is sort of like a beginner's version of a query language where you have these options you can add to get different endings.
There is one other command that's very close. That's pstree, and it does the same thing except it gives you a tree view of everything. We see system D has started all of these things. The account daemon. We've got cron jobs going. Our dbus has been launched. All these different things are running and we can see how they are related as processes, load sub processes.
Now, ps is a snapshot of what's happening at that moment, and it doesn't update, so you have to constantly run that command in order to see an updated version of the processes. There is another command we can use, which is top, which is interactive and it will run and it will update every time there's a change and provide you with the most recent information. The most common use for top is to see why your computer is running slow.
By default, it sorts these as to what's taking up the most CPU time. If you look at this and you see that your program is taking a very large amount of time, there's probably something wrong and you wanna kill that process and you wanna start it over. This works for your own programs as well, if you're running your own program and it seems to be taking a long time to execute, you can see here that maybe it's stuck in some kind of a loop and spinning.
If you hit H for help, you will see that there's several hotkeys you can use to manipulate the different processes that are going on, sorting them in various different ways. I'm gonna quit out of there, let's clear our screen so it's not cluttered, and then I wanna take a look at the command kill. The thing about kill is that it does more than what you think it would. If you think of the command kill, you think of its determinator process, which is exactly what it says here in the man info.
But, if we go down and look further, we can send signals and there is various different types of signals we can send that will do different things. Let me show you a list of some of the things you can do. There's a long list of signals that can be sent to a process. I'm gonna go over the three most common ones. First one I'm gonna cover is sighup. It originally comes from the act of hanging up the telephone and cutting the line to the process.
In the modern world, it's sent when the controlling terminal is exited and that signal is then sent to the process. When a process gets that signal, sometimes it will terminate and other times it will simply reopen the log files and reload their configuration. Sigkill kills a process immediately. I like to think of this as pulling the plug, cutting off the power immediately, and this cannot be ignored by the processes, so they have to shut down. Contrast that with the third one, which is sigterm, or terminate, which allows the process to perform housekeeping before shutting down, so it may close file handles, it may write out to a log, it may save a configuration file, and then it would terminate.
The thing about this is sometimes it can be ignored by the processes. In most cases, you want to try sigterm, and if that doesn't kill the process, then go with a sigkill. You can use kill with or without systemctrl. It's up to you how you choose to use it, but the commands are kill -s and then the signal and then the process id of the signal you wish to send the signal to.
- 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