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

  • By
  • August 6, 2023
0 Comment

19. Foreground and Background

Now, another option you have is to run the same type of command but in the background so that it’s not in the foreground waiting to be finished before you can go back to your shell to do that which we described before was called a foreground process. We run it as a background process, and that’s not that hard to do. Again, it still does everything else that we said before. It’s going to run it in the subhead shell. It’s going to do its job, execute and come back and let you know when it’s done. But you can still do more work in the parent shell without having to wait. The only thing you need to do, remember, is that when this happens is you precede the background stuff or you set it up to run in the background with the ampersand. So you type in the command with an ampersand. The ampersand says this process in the background, so it’s still going to fork, but you’re not going to be stuck waiting for it to finish.

20. Demo – Comparing Foreground and Background Processes

Well, one of the other things we can look at with processes besides killing them off is to talk about foreground and background. So I’m going to type in the command sleep 600 that killed off. As you can see, my chance for ten minutes of doing anything with this particular shell. Now, the quick and easy kill was CTRL C. It’s kind of a universal kill, all the running processes in your shell. But we can have these these programs running in the background by putting an ampersand at the end of each of our commands. So what that does now is it gives me the sleep command still running, but it’s running in the background. So I have my command line back ready for me to go PS. All right, take a look. And you can see PS shows me I’m running sleep.

Now, if I want to use the foreground, I could say, bring back to the foreground that last command, Sleep 600. And now I’m back asleep. Okay, CTRL C. Well, let’s take a look at what happens if I run this sleep command three times. I’ve got three processes going. I give you the PS. You can see them all. There 233-1323. So I’ve got that running all the time. Now I’m going to type in jobs. And you can see I have three running jobs. So I’m going to say, let’s kill all, and the names of the jobs are asleep, terminated them all. We’ll do another jobs command, don’t have any more jobs. So I found a fast way of just kind of playing around with those processes running within my shell, foreground and background.

21. Process Priority

Alright, you are going to have a lot of processes running and they’re all going to have a different priority. Now, priority just means who is more important to the operating system and gets the first call at getting time on the CPU. In other words, if you have the highest rating, which is a priority of zero or the lowest rating of a priority 127, the highest rating one is going to get more processor time time than the lowest one. Now, this always confuses me because to me priority was the game of bowling, not the game of golf. Priority meant high score wins. In this case, it’s a golf game, low score wins. But that’s okay as long as you just remember it sounds opposite of what I just said.

Things are good, but it does determine your time slice. How much time do you get? Obviously, some system processes are going to take more prevalence in this entire thing than, oh, I don’t know, some little print job running in the background. So we want it to have the mouse and the keyboard and the screen and all that stuff running at the high priorities. Now, in some operating systems, you can just flat out change priorities altogether to make something like your mouse more important and the main kernel of the operating system. In that case, things pretty much come to a crash, so you can’t really change it by a numerical value.

We just know that there is a range from zero to 127. But you can use some commands to try to give certain processes either higher or lower priority. As an example, if I’m playing my favorite game and I’m trying to create a print job at the same time, and that print job keeps interrupting my game, making it run slow, and the print job is of no. Consequence to me I might try to make the process that is my game run with a higher priority than the print process so that I get more time slice than the other. OK, that is a good anti productive example of what not to do at work, but it gives you an idea of what I’m trying to accomplish by prioritizing these different processes.

22. Viewing Priorities

Now, first you probably want to view the priorities that already exist for each of the processes. I think that’s an important factor that if you’re going to make some changes, it’s probably a good idea that you see what those priorities are and you see a PRI column. That’s the priority. And if you want to sort them, remember your top command, but you want to look at what those priorities are so that you can kind of get an idea that if I change a priority of this process, would it or what would it negatively affect, that being other processes that are running. I think that’s an important aspect that you should know of the ripple effect.

If I say, take this low priority, make it a little higher, what did I do with everything else? And then can I complain if everything else runs? Credit because you made this process prioritization. So just take a look at it first, see what those priorities are so you’ve kind of get an idea of the range where they run and maybe get an idea of how you want to affect the priority of a certain process that you are going to change. Again, you’re going to be actually using a command that makes a suggested range of changes. And so you should see what it is now, so you’ll know what that range is going to affect.

23. Setting Priorities

Alright so when we talk about setting the priorities, you have to remember you are not going to directly set those priorities. We’re going to use a command that’s called the nice command it’s a nice way to suggest a priority. Now when you use the nice command, you’re going to have a minus and positive number range I think from -20 to plus 19 range that you can use as a suggestion of how to change the priority priority. Obviously the negative value is going to suggest that you make it a higher priority by moving it closer to zero. Remember golf game the positive number is actually going to say this is not as an important process make it lower priority.

Now when you put that in, you have to also make sure you name the process and it allows the kernel to make the decision whether or not it wants to follow your suggestion. But it can then choose how to best deal with your request on a particular process. Now, when you’re ready to set that process back to normal, and especially if you didn’t even look to see what normal was, there is a command called the RENAISS which basically says reset it to the original nice command for that process. And again, knowing the process ID makes this even easier because you can reference the processes by their PIDS.

24. Renice

So as an example, you’ve got this process. You’ve got your game running at a high process. The printer is down there in the middle of nowhere, and now the print job is done. And you say, okay, well, I can put this game back to its normal setting. So you would just type in Renee, put in the process ID, and then let it go, and that would tell it to put it back to its original priority.

25. Demo – Managing Process Priorities

All right, so I have two terminal windows open again, so we can play with the processes in one terminal window being affected by another one. And I’m going to put in this Sleep 600 so that I’ve got this first terminal being inactive for me. And on this side, we saw some of these commands already, El. We’re going to list the processes for everything when grep for sleep. And if I keep on talking about sleep, I’m going to be sleepy all myself. All right, so there we’ve got the list of those processes. Actually, I’m thinking two of those processes running right now. That’s kind of why I prefer the Ox here. It’s a little easier, I think, to see these. There we go. I’ve got the one sleep that is the actual sleep command, 23 321. Seeing that’s this process here, see, I just like PS Ox.

It’s easier for me to read. And then this other one, which is the Grep command. So that’s the process that we’re dealing with right there, 23 321. Now, one of the things that we are going to look at is what is the priorities of some of these things. In fact, I’m going to make this wide screen again, run that same Grep command just so we can get an idea of some of the options and start looking at priorities, because that’s kind of what we’re going to deal with, is dealing with priorities. In fact, PS El Grep sleep might also be nice enough to give us some of those finer points of information as well. And then we’re going to start playing around with these processes. So again, PS El is giving me both processes, whereas the PS ox at least gave me each one broken down by each user, okay.

Or by each actual process. All right, so let’s start playing with stuff here and see what happens if we go out there and start changing the way in which a process runs. Now, what I’m going to do is I’m going to kill sleep. There we go. And by killing the sleep, let’s go back here to the background window. I got my prompt back. What we’re going to do is we’re going to use this command nice dash n 15, sleep 600. So what we’re doing is we’re really saying we’re going to run that sleep command again, but nice, remember now is my way of trying to get just a little bit less priority than what I had before. So now when I’m looking at my process for the actual Sleep 600, I see that it is nice, a little nicer than it was before. Let’s try the PSEL.

And when I look at the PSEL value from the first time up here, where it was running just at its regular zero, or I should say 80, I see that I said let’s add 15. And it did, and it made it a value of 95. Okay. So that was pretty straightforward. It allowed me to play around with that process and change the value of the priorities by doing that. And the next thing we’re going to do is see if we can’t go in there and do a little re nice. So a, Renee, now I’m going to run as the administrator here. Re. Nice. Now, remember, I can’t do this on the other window because it’s sleeping, and I want to subtract ten from that process. And the process is 23. Three, three, one. It looks like based on that list and boom password for the here we go. For the root.

Old priority was 15. New priority is minus ten. And let’s do that again. PSEL. So now instead of it being 80 or 90 or 95 like it was, it’s now 70. So it’s running within a higher priority. And if I do the same thing with the PS OC, we can see that it’s running with less than being as nice as it was before. All right, so that’s where PSEL, I think, shows up a little better than this because it’s a little harder to understand what’s going on with the actual value. All right, so anyway, there’s two options that you have and of course, I’m going to kill all the sleep again and everybody’s back awake. So playing with priorities, using something benign in our example is great to practice with because you’re not going to cause input output devices to be ignored or to cause things to run. Haphazardly. By the way, you do the priorities with the sleep command.

* The most recent comment are at the top

Interesting posts

IBM Certified Data Scientist: Building a Career in Data Science

In today’s digital age, data is the new oil, driving decision-making and innovation across industries. The role of a data scientist has become one of the most sought-after positions in the tech world. If you’re considering a career in data science, obtaining the IBM Certified Data Scientist certification can be a game-changer. This certification not… Read More »

How to Balance Work and Study While Preparing for IT Certification Exams

Balancing work and study while preparing for IT certification exams can feel like an uphill battle. Juggling a full-time job and intense study sessions requires careful planning, discipline, and creativity. The pressure of meeting job responsibilities while dedicating time and energy to study can be overwhelming. However, with the right strategies and mindset, you can… Read More »

10 Highest Paying IT Certifications

In the ever-evolving world of information technology, certifications are more than just a feather in your cap – they’re a ticket to higher salaries and advanced career opportunities. With the tech landscape constantly shifting, staying updated with the most lucrative and relevant certifications can set you apart in a competitive job market. Whether you’re aiming… Read More »

Strategies for ISACA Certified Information Systems Auditor (CISA) Exam

Are you ready to take your career in information systems auditing to the next level? The ISACA Certified Information Systems Auditor (CISA) exam is your ticket to becoming a recognized expert in the field. But let’s face it, preparing for this comprehensive and challenging exam can be daunting. Whether you’re a seasoned professional or just… Read More »

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 »