Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3-1 (50 points) Write a C program to calculate the total size of the files in a directory and the sub-directories of the directory.

Problem 3-1 (50 points)

Write a C program to calculate the total size of the files in a directory and the sub-directories of the directory.

Detailed Requirements:

1. Name the program in the pattern SECTION#_NJITID#_1.c. SECTION# is the three-digit section number of the CS288 section you registered (e.g., 001, 101, don't miss the leading 0s). NJITID# is the eight-digit NJIT ID (Not your UCID, Rutgers students also have NJIT IDs). 1 means this is the first problem. So your file name is something like 001_00123456_1.c (DO NOT COPY THIS AS YOUR FILE NAME!). The grader may use a script to find and test your programs. The script will not find your program if the program has a different name.

2. Note that the total size should include the sizes of sub-directories (directories are also files), but not the size of the top-level directory.

When your program is run against the following directory tree (files are not included in the diagram):

your program needs to add the sizes of the files under directories dir1, dir2, ..., dir13, and the sizes of directories dir2, dir3, ..., dir13.

3. If a file is a symbolic link, the symbolic link should not be dereferenced. So the size of the symbolic link is added to the total size, not the size of the file pointed by the link.

4. The pathname of the directory is specified in the command line. The format of the command for running the program is as follows (Important! If you don't follow strictly, the script testing your program may not be able to run your program correctly, and you may get lower grades).

./your_program pathname_of_directory

5. To facilitate testing, your program should print out ONLY the total size in bytes, i.e., ONE number, nothing else.

6. Test your program on one of the afs servers (afsN.njit.edu, where N is an integer from 1 to 36). Compile your program with gcc. Run the executable file obtained. Compare the result printed out by your program with the result obtained with command

du -abc pathname_of_directory

(look at the number printed out by du on the last line)

Grading:

1. The executable file can be successfully generated with gcc ---- +10 points

2. The program can finish within 3 minute without crash when it is run with the following command: ---- +10 points

./your_program /usr/share/man

3. Your program can print out correct result for a directory containing only regular files and NO symbolic links: ---- +20 points

4. Your program can print out correct result for a directory containing symbolic links and regular files: ---- +10 points

============

Total: 50 points

Problem 3-2 (50 points)

Part 1: Write a C program that takes an integer command line argument n, spawns n processes that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each process needs to print out the random number it generates.

Part 2: Write a pthread program that takes an integer command line argument n, spawns n threads that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each thread needs to print out the random number it generates.

Detailed requirements:

1. Name the programs in the pattern SECTION#_NJITID#_2.c and SECTION#_NJITID#_3.c . SECTION# is the three-digit section number of the CS288 section you registered (e.g., 001, 101, don't miss the leading 0s). NJITID# is the eight-digit NJIT ID (Not your UCID, Rutgers students also have NJIT IDs).

2. The programs should analyze arguments in the command line, in order to determine the number of processes/threads to be created. The format of the command for running a program is as follows (Important! If you don't follow strictly, the script testing your program may not be able to run your program correctly, and you may get lower grades).

./your_program -n number_of_processes_or_threads

3. The programs should print out numbers only, one number on each line. The sum should be printed on the last line. For example, when 10 processes are used, 11 numbers are printed out on 11 lines for each program --- 10 random numbers on the first 10 lines and 1 sum on the last line.

Grading for Each Program:

1. The executable file can be successfully generated with gcc ---- +5 points

2. The program can finish within 1 minute without crash when it is run with the following command: ---- +5 points

./your_program -n 10

3. The processes/threads can be correctly generated. The number of processes/threads matches the command line argument. --- +5 points

4. A correct number of values (random numbers and the sum) are printed out, one on each line. --- +5 points

5. The sum is correctly calculated. ---- +5 points

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions