Question

Programming Assignment You will learn how to deal with multiple processes and use a process pool....

Programming Assignment

You will learn how to deal with multiple processes and use a process pool.

You will write a program creating multiple processes (p=5).

Each process will receive integer value (y) and compute y multiplying by 3 (y*3). A collection of y values is a list of integers [0 to 9].

You must use a process pool, so you need to map these 5 processes to take one value from the list and compute y*3 for all y.

Reuse these process whenever available and do the following: Your program should print out the following three.

(1) Show the output of y*3 in list (in increasing order).

(2) Show the output of y*3 in random order of process mapping.

(3) Show each process ID (PID) of the process being mapped in list. When doing the above, let them sleep for 5 seconds each.

Execution example: >> python3 ./assignment2.2.py

Output of (1): Output in order: [0, 3, 6, 9, 12, 15, 18, 21, 24, 27]

Output of (2): Output in random order:

0

9

3

6

12

15

18

21

27

24

Output of (3)

PID: [19473, 19475, 19474, 19472]

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

(1)

import multiprocessing

import os

def multiplyThree(x): #function to print 3 times x

print(x*3)

if __name__=="__main__":

for i in range(10): #running a loop for i=0 to 9

p1=multiprocessing.Process(target=multiplyThree,args=(i,)) #creating a thread for every value of i

p1.start() #starting the thread

p1.join() #making sure that this thread is executed before the ones created later

Output:

(2)

import multiprocessing

import os

def multiplyThree(x): #function to print 3 times x

print(x*3)

if __name__=="__main__":

for i in range(10): #running a loop for i=0 to 9

p1=multiprocessing.Process(target=multiplyThree,args=(i,)) #creating a thread for every value of i

p1.start() #starting the thread

Output:

(3)

import multiprocessing

import os

def multiplyThree(x): #function to print 3 times x

print(x*3)

if __name__=="__main__":

for i in range(10): #running a loop for i=0 to 9

p1=multiprocessing.Process(target=multiplyThree,args=(i,)) #creating a thread for every value of i

p1.start() #starting the thread

print(p1.pid) #printing pid of thread

Output:

Add a comment
Know the answer?
Add Answer to:
Programming Assignment You will learn how to deal with multiple processes and use a process pool....
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
  • Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine...

    Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....

  • In this lab you will convert lab5.py to use object oriented programming techniques. The createList and...

    In this lab you will convert lab5.py to use object oriented programming techniques. The createList and checkList functions in lab5.py become methods of the MagicList class, and the main function of lab6.py calls methods of the MagicList class to let the user play the guessing game.                              A. (4pts) Use IDLE to create a lab6.py. Change the 2 comment lines at the top of lab6.py file: First line: your full name Second line: a short description of what the program...

  • Questions: 1) Write a simple program to create three processes using fork() commands. Use any three...

    Questions: 1) Write a simple program to create three processes using fork() commands. Use any three of the six system calls to show how each child process executes new sub-programs using exec’s minions. Show the output of each of the child process with different data samples.   2) Write a simple program in your Linux environment using C++ to identify PID, PPID and GID for the processes created in Question 1 and display the real and effective user ID.   3) Modify...

  • Part 2. System Programming and Process Management You are asked to develop basic system programmi...

    Can someone help me create this program for Linux. Part 2. System Programming and Process Management You are asked to develop basic system programming including process creation and termination on a Linux platform in this part of programming project. You are asked to create multiple children processes to work under one parent process. In theory, children processes can do their own work separately or cooperatively to accomplish a task. In this assignment, these children processes simply print out a "hello"...

  • I'm try to complete an Operating Systems assignment where we have 8 processes, and each process...

    I'm try to complete an Operating Systems assignment where we have 8 processes, and each process has between 14-18 bursts. We have to do a FCFS simulation, SJF simulation, and MLFQ simulation. I am well aware of how to calculate everything for the processes when we just have one set of bursts to deal with, however these processes have way more than that. I am a very visual learner, I would love if someone could explain to me how to...

  • Java Programming: Make a Java program with two processes, a producer and a consumer. If you...

    Java Programming: Make a Java program with two processes, a producer and a consumer. If you want to use another language, clear it with me first. The producer process consists of a loop that writes the loop count (a value from 0 to 4) into a variable that it shares with the consumer process (this variable is to be initialized to 100). On each pass through the loop, before the producer writes into the shared variable, it does a random...

  • Make a Java, program with two processes, a producer and a consumer. The producer process consists...

    Make a Java, program with two processes, a producer and a consumer. The producer process consists of a loop that writes the loop count (a value from 0 to 4) into a variable that it shares with the consumer process (this variable is to be initialized to 100). On each pass through the loop, before the producer writes into the shared variable, it does a random wait of from one to three seconds (compute a new random wait value on...

  • Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS)...

    Please help me create this CLI CPU Scheduling Simulator in java: First Come First Serve (FCFS) Round Robin (RR) Process information The process information will be read from an input file. The format is: pid arrival_time burst_time All of fields are integer type where: pid is a unique numeric process ID arrival_time is the time when the task arrives in the unit of milliseconds burst_time the is the CPU time requested by a task, in the unit of milliseconds The...

  • Use the method of completing the square to find the standard form of the quadratic function....

    Use the method of completing the square to find the standard form of the quadratic function. f(x) = x2 - 8x + 5 y = State the vertex and axis of symmetry of the graph of the function. axis of symmetry X = vertex (x, y) = Sketch the graph. 30 Graph Layers 27 24 21 After you add an obje can use Graph Layers properties. 18 15 -12 Fill 19 6 3 -30 -27 -24 -21 -18 -15 -12...

  • The answer need to write in C programming. QUESTION 2 Write a program using array to...

    The answer need to write in C programming. QUESTION 2 Write a program using array to generate a multiplication table based on the user's input. For example if user enter 5 as input then a multiply table for 1 to 5 is printed as output as shown in Figure Q2. There are three main steps in this program which are: Print rows (a) (b) Print columns Print multiplication of data inside table (c) Select C:\example1 \bin\Debuglexample 1.exe enter the value...

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