Question

Write python script that implementing the following: 1. Print PID of itself. 2. If the running...

Write python script that implementing the following: 1. Print PID of itself. 2. If the running OS is linux; print loadavg. 3. Take and print “5 min loadavg” value and cpu core count. If the loadavg value is near (or close) to the cpu core count (hint: nproc - 5min loadavg < 1) then exit script.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.py saving... 1 import os 2 import platform PID is: 1320 --==-=-load averge--------- Load average over the last 1 minute:

code in text

import os

import platform

print(" PID is:",os.getpid())

platfrom_name=platform.platform()

platfrom_name=platfrom_name.lower()

load_one_min, load_five_min, load_15_min= os.getloadavg()

if platfrom_name.find("linux")!=-1:

print("-------------load averge-------------------------------")

print("Load average over the last 1 minute:", load_one_min)

print("Load average over the last 5 minute:", load_five_min)

print("Load average over the last 15 minute:", load_15_min)

print("---------------------------------------------------------")


cpu_count=os.cpu_count()

print("Numbers of CPUs in the system is :", cpu_count)

print("Load average over the last 5 minute:", load_five_min)

if(cpu_count-load_five_min<0):

print(" exit the script ")

""" any doubt please comment if you like my answer please thumbs up"""

main.py saved 1 import os 2 import platform PID is: 1320 -------------load averge-------- Load average over the last 1 minute: 6.66 Load average over the last 5 minute: 4.72 Ldad average over the last 15 minute: 4.26 print(" PID is:",os.getpido) Numbers of CPUs in the system is : 4 Load average over the last 5 minute: 4.72 exit the script platfrom_name=platform.platform() platfrom_name=platfrom_name. lower() load_one_min, load_five_min, load_15_min= os.getloadavg() 9 11 if platfrom_name.find("linux") !=-1: print("-------------load averge-------------------------------") print("Load average over the last 1 minute: ", load_one_min) print("Load average over the last 5 minute: ", load_five_min) print("Load average over the last 15 minute:", load_15_min) print(" cpu_count=os.cpu_count) print("Numbers of CPUs in the system is : ", cpu_count) print("Load average over the last 5 minute:", load_five_min) if (cpu_count-load_five_minco): print(" exit the script") *" any doubt please comment if you like my answer please thumbs up **

Add a comment
Know the answer?
Add Answer to:
Write python script that implementing the following: 1. Print PID of itself. 2. If the running...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Script format please! 1. Write a script that takes in three integer numbers from the...

    Python Script format please! 1. Write a script that takes in three integer numbers from the user, calculates, and displays the sum, average, product, smallest, and largest of the numbers input. Important things to note: a. You cannot use the min() or max() functions, you must provide the logic yourself b. The calculated average must be displayed as an integer value (ex. If the sum of the three values is 7, the average displayed should be 2, not 2.3333). Example:...

  • Use Python Write a script to perform various basic math and string operations. Use some functions...

    Use Python Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals the remainder of 5 divided by 3 Built-in functions abs, round, and...

  • Exercise 1 - Create a List to Sum Values Write a python script that sums the...

    Exercise 1 - Create a List to Sum Values Write a python script that sums the values in a list called add_list that contains the following values: (10, 2, -4, 8). Make sure you include a for loop when iterating through the list to sum the values. Take screenshots of the code and output. Exercise 2 – Create a Dictionary Write a python script that prints a dictionary where the key numbers are 1, 2, 3, 4, and 5 and...

  • Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt...

    Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt formatted like this:      Tuesday we have Joe McHungry and Paul McHungry Wednesday we have Cindy Johnston and Paul Paulsen Thursday we have Amin Mirzaei and Atefeh Mirzaei gets turned into that: The McHungry on Tuesday Cindy and Paul on Wednesday The Mirzaei on Thursday 2)Write a script that takes as argument a port number. It returns the next port that is not assigned to...

  • For this Linux script, answer the questions following it: # Sort lines 7 - 26 of...

    For this Linux script, answer the questions following it: # Sort lines 7 - 26 of the file BEGIN { idx = 1; while (getline line<"makefile" ) { data[idx] = line; idx++; } for (idx2 = 7; idx2 <= 26; idx2++) { data2[idx2 - 6] = data[idx2]; } count = asort(data2); for (idx3 = 1; idx3 < 7; idx3++) { print data[idx3]; } for (idx3 = 1; idx3 <= 20; idx3++) { print data2[idx3]; } for (idx3 = 27; idx3...

  • Write a python program to print a poem of your own choice. Then count how many...

    Write a python program to print a poem of your own choice. Then count how many words in each line, use a print statement to add the number of words in each line and display it. Hint: use print(3+5+4+6), for example. My poem: 'Tis better to have loved and lost Than never to have loved at all.'

  • Part 1: Using Idle Write a Python Script that Does the Following 1. At the top...

    Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...

  • 1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write...

    1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x):     if x in "aeiouyAEIOUY":         return True     else:...

  • 1. (Expressions) Write Python expressions for the following tasks. Print the results of the expressions using...

    1. (Expressions) Write Python expressions for the following tasks. Print the results of the expressions using the ‘print’ function. Compute the product of 11111111 with itself. How often does 91 go into 1000? (Integer value) What remainder does 91 leave when divided into 1000? You scored 90/100, 46/50, 55/60 and 66/70. What is your best score on these four works? A KB (kilobyte) in information technology is really 1024 bytes (not 1000 bytes), where 1024 is 2 raised to the...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT