$29
Write a program in C that does the following :
1) Opens two pipes , one to the ls command and the other to sort . display output on the screen.
Using threads , parallelize a sequential program to compute the sum of an array of size 50 of integers from 1 to 2500 . Use random number generator in order to generate numbers between 1 and 2500.
Takes the three positive integers m, n and r from its commend line arguments, using fork , create three child processes, wait for them to complete, and exit. The first process sorts m random integers using the bubble sort, the second computes the factorial of n, and the third process computes hailstone sequence .
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1.
– Husain Gholoom – Lecturer in Computer Science Page 1
CS4350 -‐ Unix Programming
Sample Run
./a.out 8 5 7
Welcome to Husain Gholoom’s Program
This program will do the following :
• Opens two pipes , one to the ls command and the other to sort . displays the output on the screen.
Takes the three positive integers m, n and r from its commend line arguments, using fork , create three child processes, wait for them to complete, and exit. The first process sorts m random integers using the bubble sort, the second computes the factorial of n, and the third process computes hailstone sequence .
Using threads , parallelize a sequential program to compute the sum of an array of size 50 of integers from 1 to 2500 .
1- Performing ls | sort
4350-Lecture-5 - IO-L3.docx
Alice3
Desktop
Documents
Downloads
.
.
.
– Husain Gholoom – Lecturer in Computer Science Page 2
CS4350 -‐ Unix Programming
2- Bubble Sort Process Started Input Number : 8
Generated Random Numbers :
8 31025 5 230 Sorted Sequence:
3 5 6 8102530 Bubble Sort Process Exits
Factorial Process Started
Input Number 5
Factorial Number f(5) is 120
Factorial Process Exits
Hailstone Process Started
Input Number 7
Hailstone sequence of 7 is : 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
Hailstone Process Exits
The main program should print the following output:
Main Process Started
= 8
Number of
Random Numbers
Factorial
Input
= 5
Hailstone
sequence Input
= 7
Bubble Sort Process Created
Factorial
Process Created
Created
Hailstone
sequence Process
Main Process Waits
Main Process Exits
– Husain Gholoom – Lecturer in Computer Science Page 3
CS4350 -‐ Unix Programming
3- performing int[50] sum using two threads... The total sum is 1963
Program by Husain Gholoom
– Husain Gholoom – Lecturer in Computer Science Page 4
CS4350 -‐ Unix Programming
Rules :
The programs must be syntactically and logically correct. The program will be tested using the Zeus ( Unix OS ) at the university.
The programs must be documented and your names , course and section number , your group number, assignment number , due date , and instructor’s name should be included as part of your program documentation. A brief description of the program must also be included
Must properly format the output as shown above .
You must upload your solution using TRACS – Make sure you include the above as comments in your program. Make sure that you name your homework document as follows :
Z#PA6.c where # is your serial number
For example Z100PA6.c
Every group member must also upload the program.
You must also turn in hard copy of your source code on the due date class time. The hard copy must be stapled. if you are unable to turn a printout in during class, you can turn it in to the computer science department office (Comal 211 ) before the deadline. They will date & time stamp it and they will place it in my mailbox. Only one hard copy per group.
No late assignment will be accepted.
– Husain Gholoom – Lecturer in Computer Science Page 5
CS4350 -‐ Unix Programming
Must place the following information on top left of the first page of your assignment as comments
NAME : ______________________ CS 4350 – Unix Systems Programming
Serial Number:
Group Number:
Assignment Number: ___________
Due Date: 5 / 1 / 2019
DO NOT slide hard copy of your program under my office door.
– Husain Gholoom – Lecturer in Computer Science Page 6
CS4350 -‐ Unix Programming
The following points will be deducted if :
Compilation Errors, missing electronic copy , missing the hardcopy
, not written in c programming language, submitting .zip file,
submitting files other than
.c
… etc
( -10
points )
•
Logical Errors (
at least 1
points )
•
Other ( at least
1.50 points )
if any of the following takes a
place :
Unable to read the source code due to unclear printing
Incorrect Output format.
Incorrect program file name.
Hard copy is not stapled.
More than one hard copy per group.
Incorrect Style such as but not limited to Missing Header comments, missing footer comments, not replacing my name with your name, missing serial number , missing section number , missing program documentation , not replacing my name with your name … etc.
– Husain Gholoom – Lecturer in Computer Science Page 7