CompTIA Linux+ XK0-005 – Unit 07 – Process and Module Management Part 2

  • By
  • August 5, 2023
0 Comment

12. The top Command

Now, when you do take a look at some of the information, it might not be in the order that you like. In other words, you want to see the top offenders, whatever you want to call those processes first. So remember that with most of these, you have a top command. Top command just says, show me the top in order of the offender. So if you care about the top CPU use, or the top time it’s been running, or the top amount of memory, it’s just sorting the information in an order that’s important to you.

13. Demo – Viewing Processes and Devices

All right, we’re going to kind of find some other ways to show you some processes. We showed you already, some with the PS tree. But in this case we’re going to show you a different set of command lines that help show processes differently than that tree view. Now PS, you run that and it shows you a small list of processes. Those processes, by the way, are, are just the ones running in this shell. Now, you may have noticed I made this shell a full size, a full screen. I haven’t done that in most of my other examples. And I did that because the output of this particular set of commands is going to be just a bit unwieldy. And you’ll see what I mean. What we’re going to do now is try to take a look at some other options. We’ll PS help, let’s pipe this so I can’t spell help, let’s pipe this to the More command.

And so we see some options here that we’re going to play with. We can see things like all processes with the E. Let’s see what other options do we have here that we might choose, might go with F for the extra full information for the output format as well. Let’s hit the spacebar. Did that already. Now it was the uppercase F for the extra full format, or we might choose the lowercase F for the ASCII art force. That sounds interesting. So anyway, some options that are out there. Let’s try that. Let’s try PS E. And so now that’s showing us all the processes. And of course without the More command that I piped it into, I have to scroll up so you can see that there’s quite a few processes and I put it into a nice numerical representation. I can try the Psf and the Psf just gave me full details.

Yeah, I thought that was better than the O F, which is the option would be to give you something really cool and maybe I want to do both. So here is the problem. The PSE gave me everything, the Psf gave me the full details, but just of what’s running in my shell. So I guess E and F would give me everything with full details. All right. And of course then you might pipe it with the More command so you can start looking at it one at a time as far as the pages go. Okay, so that’s not so bad. But another option you have is the PSX command. The X command is going to show me all of the processes for all of the shells that are running on this particular system, unlike just the PS command. And it’s going to list the process priority, the state, the CPU time associated with each of those as I ran it, at least at the time that I ran it.

But again, the Psax piped into a More might be just a little bit more helpful. Now there is another option with the Psax. It’s the PS ox. And I only say that because aux in the world of routing is considered the auxiliary port. So I’m used to calling it the ox aux. Anyway, now this one’s going to show me that same set of processes but it gives me a little more verbose information. In fact, this kind of command is giving me the percentages of CPU time and memory, start time and even the user ID that’s associated. Now this last output would be kind of fun to deal with with the Top option. The Top programs job is to take that same set of data that I just ran and basically start giving me new reports, putting things you notice what it’s doing,

it’s sorting things for me by these different values. Now, if you wanted to know what else can you do with this top and by the way, the Top program is still running. I don’t have my cursor back. It’s still showing me the top. If I type H, it gives me the help. Now the help allows you to, toggle summaries load averages. You can see there’s quite a few options to specify a specific user, maybe if that’s what you want to do. Q to quit to get out of there. Now Q is to quit the Top program, right? Now it says that if I hit any other key that’ll get me out of that help mode. So it was very careful, you didn’t hit the queue. If I type user here and say the user trainer, then it shows me all those processes associated with that user and again, it just gives me the option to put in there, leave it blank for all. And of course when I’m done I can hit the letter Q and that allows me to quit out of there.

Now, if I were to go out there and play with a lot of the other options that you have with Top as well, so you can kind of get an idea of how easy it is to see that in in fairly real time. Now that again was just looking at some of these different processes. Now there is also another directory, let me clear my screen. There’s also a corollary. We would say to the proc directory is the sys directory and that’s for the synthetic file system. And there I would find, let me do the LS commands. There you would find the directories and files that represent devices, buses, modules that are currently loaded into our module. And it’s really to say if it’s not a process but it’s being used, then it’s in the SIS directory. So I’m going to do an LS with the sys directory. And so of course we see things like power module kernel, class buses and the rest.

And let’s take a look at the buses, SIS bus and what I expect to see are PCI buses, USB buses, scuzzy buses, game ports, lots of things, sound buses, lots of options that are showing me what’s happening, what’s running, and maybe I can even use that same option here with the bus. Let’s go into USB and look at devices in USB One. And so there you can kind of see an idea of what’s there and the information about the buses. In fact, let’s leave off USB One just so you can see all of the devices that are out there, because we have two buses that are running. And so there you can see both of them listed for us. All right, so anyway, it’s just some nice ideas to figure out what kind of information you can pull out of the information. You can even cat some of the information in there to see what on the screen anyway, what kind of information shows up.

So let’s try that out. Let’s cat the Sys Bus USB, the devices, USB One, and let’s see if there’s any product information associated with that. And that’s just the host controller. We can try USB two. And again, just the different host controllers for the two USB buses. So it’s just showing you the information stored in the configuration file that’s in this case called Product. Now, there was another time that we were showing you some examples of how to pull out the information to show you about the different drives that were stuck in these USB. Well, that information came from this Sys folder that you’re seeing here as it’s being used by the operating system, as we said, but not really a process. So there we looked at the processes and those things that they would call the synthetic processes.

14. Killing Processes

Now when it comes time to deciding you’ve got some sort of rogue or zombie process or I called it a misbehaving process and you want to kill it, you have some options with a kill command. Now the options are values, numbers that we use as signals or types of signals. The default is what we call the SIG term or the terminate which is a value of 15. It’s your default kill command. Now we can be a little little more polite. We have a basic what we call the SIG or the signal for hang up. So it sounds like we’re saying SIG hub the way it’s described. Sighup just means hang up. You’re saying politely please shut this thing down. You might just not want to kill it. But interrupt ones. There might be some foreground process that’s busy, it’s doing stuff and you’re like you know what, you need to just stop right now, back off, let us do something else. You can come back later.

That would be the interrupt or the SIG int it interrupts a foreground process. A polite way to kill a process and save what it was doing to a core dump file is to send a quit command that’s the SIG quit. Now finally the absolute kill. The number one telling the operating system, the kernel itself, stop it, ignore it, don’t deal with it anymore. Kill the thing is the option nine, the SIG kill sounds pretty bad but it’s important to know that you can choose one of these in the kill command or just say kill and it would be the default kill command trying to get the process to stop and go away. The default kill is the kind of command that a parent process would issue to one of its child processes when it’s done. So it’s a very normal type of command that we use to basically stop processes.

15. Other kill Commands

All right, there are other types of commands that you can add with the kill. One of them is the PGRP command. There you are sending information, regular expressions about matching processes to kill. What does that mean? That means we’re trying to kill things that match certain patterns and there might be certain processes for one program that might all start with the same letters and so we want to kill all of those. The P Kill command kills any process you name. Now the Kill all that’s great. It kills all processes by whatever name you provide. That means parents and all their children. You can use some signal trapping.

That means that there are some processes that might be immune to the SIG term command for killing. So use the SIG Kill command for those. Now that’s great. Some super processes that say that kill command is for somebody else you can still kill those things with the SIG Kill. We call it signal trapping and again, remember if you do kill a parent the idea is that it should also kill any of the child processes that started with that. I’m never going to say that’s a guaranteed promise but if it’s not you now have the ability to look at those processes, list them and kill off those that are as we’ve said, rogue or zombies just kind of running with no apparent purpose.

16. Demo – Managing Processes

All right, we’re going to monitor some processes. And to do that, I should have to have two terminals open. So I’m going to open up two of them right now. And we have to arrange these things so that we can make it look kind of nice. So let’s see if I can I can do that here for our little viewing pleasure. Make that one nice and nice and narrow. Let’s go. Make this one nice and narrow. So there we go. We’ve got two windows open for you, like we said, trying to go at the same time. Now what are we going to do is we’re going to put one of these four things to sleep. So I’ll come up to this first one and I’m going to type sleep 600. That’s 600 seconds. That’s ten minutes. So come back in ten minutes and that one will be away. So here I am. I don’t get anything. I’m hitting arrow keys, by the way. It’s just sleeping. It’s not going to let me have any process or any chance to get to the tab.

Now over here, this terminal is wide awake. I’m going to type in the PSL because we’re going to list our processes and I want to look for specifically sleep. And there you see absolutely nothing. And the reason for it is it’s running, not on this shell, but on this shell. Of course, I can’t see this shell because it’s asleep. So the PS command probably would be best suited if I added the E in front, which means show me all of them. And there we can see that it is indeed sleeping. That’s at least the type of information we’re seeing right now. And very easily enough, we said, okay, well, we’ve got that PS stuff. In fact, you could actually remember the PS Ox was another command that we had where we could look at all of those different processes.

And of course, I just jammed right on through. In fact, let’s maximize that screen real quick and let’s just do the PS socks again because it’s so much easier to read it, I think, when you have it set up here. And again, probably would have been actually good to pipe that PS Ox to the Grep sleep and see if we can get more information. There we go. So now we have the sleep information. Again, we saw the time. In fact, the last process we just also ran, which showed me the information as well, is useful. I’m scrolling up here just so you can kind of get an idea of the column headings, because what we’re going to do is going to kill that thing. But we need to have the process ID so you can kind of see why I liked using the PS or the PS Ox from the last time.

And of course, I again gripped it with the sleep. So I can see that right there. There’s that process. I’m going to copy that information because I don’t want to remember 23 to 84, but I just did. Okay, so now what we’re going to do is try to see if we can kill that process. And I’m going to do a little kill with a little bit of help. So almost sounds like I’m actually trying to get some help in killing processes here. All right, so I said it didn’t like the actual help, so let’s try to do Help kill. If that doesn’t work, then we’ll go from there and do the man pages. All right, again, the kill probably would have been better to have a little wider screen. And it talks about the different types of processes, the different signals that I can send to kill these things off. We talked about that throughout the lecture portion, that some signals are asking politely for things to go.

Sometimes they’re telling it to go away right now. Well, let’s give this a shot. Let’s kill that process. You might not remember what it is, but hey, that’s why I have paste for Kill That Process with the signal 15. And actually, I’m sorry, I’ve got this in the wrong end. Let’s do the dash in and signal 15 and then put in the Process ID. So I get this in the right order here. So paste that in and hit enter and look at that. Right away, my, my command line came back and no, it hasn’t been ten minutes. It wasn’t just on, on that perfect timing there. So let’s go back to sleep. I’m back to sleep. So again, we got the same problem over here. We don’t know what that process is. And by the way, I don’t expect it to be the same one that we had before because it was a new process. In this case, it looks like this particular one.

The Sleep 600 is process 23 293. So I’m going to copy it again and we’ll try some of the other kill signals. Let’s try the kill N. I’ll send it to signal nine and the new Process ID. Pop that in there, try that off. And there you can see killed, terminated and killed. Again, different commands that we talked about before. And if we really wanted to, we could have actually probably just put an AP kill for the word sleep and killed everything. But it’s just, again, showing you that you always have some control because of the command line. So if you open up something shell and something is misbehaving, you can open up another shell, find that process, kill it, get it out of your way, and go back to work. So that was our process management or actually the killing of our processes.

17. Topic B: Process Priority and Execution

All right. So now we’re going to talk about how to prioritize our processes and deal with their execution. I don’t mean killing them. That was the last section. What I mean is talking about them running in the foreground or the background.

18. Process Forking

First of all, let’s talk about process forking. Well, this is how it works. You are going to basically start a shell, run a command, and when you run that command, this command runs within what’s called a subshell. That’s the fork. It says, okay, I’m going to run the command that you said. I’m going to fork off, open up a subshell, you might not even see it, and run that command within the sub shell. When that subshell is done, I’ll come back to the main shell, hopefully that it doesn’t die or stall or need to be killed. I’m going to come back to the main shell and say, okay, I’m done.

Now, what’s your next command? And then when it’s done, the parent shell displays the prompt. Again, the downside to this forking, and I’m not saying that you can avoid it, but the problem here is that you can’t run other commands unless you open up another shell to run another command. So you kind of stuck or at the mercy of whatever command you just ran within that shell. But that’s still what the forking does, is you basically started a shell. That was a command. You ran a command, started a subshell, forked off, ran over there, came back. When it’s ready or done, and you’re ready to do another command.

Comments
* The most recent comment are at the top

Interesting posts

Preparing for Juniper Networks JNCIA-Junos Exam: Key Topics and Mock Exam Resources

So, you’ve decided to take the plunge and go for the Juniper Networks JNCIA-Junos certification, huh? Great choice! This certification serves as a robust foundation for anyone aiming to build a career in networking. However, preparing for the exam can be a daunting task. The good news is that this guide covers the key topics… Read More »

Mastering Microsoft Azure Fundamentals AZ-900: Essential Study Materials

Ever wondered how businesses run these days without giant server rooms? That’s the magic of cloud computing, and Microsoft Azure is a leading cloud platform. Thinking about a career in this exciting field? If so, mastering the Microsoft Certified: Azure Fundamentals certification through passing the AZ-900 exam is the perfect starting point for you. This… Read More »

The Impact of Remote Work on IT Certification Exam Processes

With remote work becoming the new norm, it’s not just our daily routines that have changed but also how we tackle IT certification exams. Gone are the days of trekking to testing centers; now, your living room can double as an exam room. This shift has brought about some fascinating changes and challenges. Let’s dive… Read More »

IT Risk Management: CRISC Certification Exam Essentials

Do you ever feel like the IT world is moving at warp speed? New tech seems to pop up every day, leaving you wondering how to keep up and truly stand out in your field. Companies are increasingly concerned about online threats, data leaks, and meeting legal requirements. That’s where the CRISC (Certified in Risk… Read More »

The Ultimate Guide to Mastering Marketing Automation for Email Wizards

Hey there, email aficionados! Welcome to your new favorite read – the one that’s going to turbocharge your email marketing game. You’re about to dive into the captivating world of marketing automation, a place where efficiency meets effectiveness, letting you boost your campaigns without breaking a sweat. Get ready to discover how automation can not… Read More »

Master YouTube Marketing with These 10 Powerful Steps

Welcome to the dynamic world of YouTube marketing! Whether you’re a seasoned pro or just getting started, harnessing the power of YouTube can significantly boost your brand’s visibility and engagement. With over 2 billion monthly active users, YouTube offers a vast audience for your content. But how do you stand out in such a crowded… Read More »

sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |