Advertisement
xdxdxd123

coursera linux end process week 5

Apr 29th, 2018
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. Introduction
  2. In this lab, you'll use the new commands you learned to do some process maintenance on a Linux virtual machine.
  3.  
  4. Go ahead and connect to the linux-instance Google Cloud instance now. As a reminder, your machines are available in Google Cloud Console under Compute Engine -> VM instances. If you're having difficulty connecting to your instance, no worries! Just follow the steps outlined in the Accessing Qwiklabs reading for detailed instructions on how to connect
  5.  
  6. Head's up: You'll experience a delay as the labs initially load (particularly for Windows labs). So, please wait a couple of minutes for the labs to load. Please also make sure to access the labs directly through Coursera and not in the Qwiklabs catalog. If you access the labs through the Qwiklabs catalog, you will *not* receive a grade. (As you know, a passing grade is required to matriculate through the course.) The grade is calculated when the lab is complete, so be sure to hit "End Lab" when you're done!
  7.  
  8. You'll have 60 minutes to complete this lab.
  9.  
  10. Terminating a specific process
  11.  
  12. The ps -aux command allows you to list all currently running processes on a Linux machine. However, the list of processes is often super long, which makes finding a specific process pretty tough. To filter the processes you're interested in, you can pipe the output of ps through grep.
  13.  
  14. There are two "malicious" processes currently running on your machine, called "totally_not_malicious". You can run ps and grep to find them, using this command:
  15.  
  16. ps -aux | grep "totally_not_malicious"
  17. You should see output similar to this. The top two lines are the two processes, while the last line is the grep process you just used to search for them. Check out the four-digit numbers on the left of each of the rows; these are the process IDs.
  18.  
  19.  
  20.  
  21. To stop a process, you can use the kill command. You need to use sudo to have permission to stop them. You also need to specify the ID of the process, which will likely be different on your machine than what's shown above (the ID is outlined in light blue):
  22.  
  23. sudo kill [PROCESS ID]
  24. After killing the processes, you can verify that they're no longer running by running the original command again:
  25.  
  26. ps -aux | grep "totally_not_malicious"
  27.  
  28.  
  29. Terminating multiple processes
  30.  
  31. There are also multiple processes running on your computer containing the word "razzle". You can find them in the same way that you found the previous process using ps. Because grep doesn't look for full matches, it can be used to find any process that contains a specific substring:
  32.  
  33. ps -aux | grep "razzle"
  34. The below shows all six processes that contain the word "razzle". (Again, you can ignore the last process because it's the process running grep.)
  35.  
  36.  
  37.  
  38. To kill each of the processes, you can use the same kill command as before, substituting in each process ID:
  39.  
  40. sudo kill [PROCESS ID]
  41. To verify that the processes were successfully stopped, you can use the same command you used to find them in the first place:
  42.  
  43. ps -aux | grep "razzle"
  44. You should only see the process for the grep command, indicating that the other processes are no longer running:
  45.  
  46.  
  47.  
  48. Conclusion
  49.  
  50. Wohoo! You've successfully used ps to find processes on Linux, and used kill to end them. These are common Linux commands, so we recommend you practice until you feel comfortable using them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement