Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

Assignment: Exec, Signals and Time Representation

Part I: Using the exec function.

Write a main program that launches 3 child programs. Each child does the same thing but in a slightly different way.

a. The first child executes a subroutine with 2 arguments - a delay in microseconds and an exit code. The subroutine announces its pid and reports on its arguments, goes to sleep for the specified number of microseconds and then exits using the exit code. (1)

b. The second child uses one of the exec functions to pass the same two arguments to a 2nd program using argv. To do this you should convert the numbers to strings using either sprintf or asprintf. The 2nd program recovers and reports these values from argv along with its pid, then goes to sleep for the specified number of microseconds and then exits using the exit code. (3)

c. The 3rd child uses another of the exec function to pass the same two arguments to a 3rd program using envp. To do this you should convert the numbers to environment variable strings, ie: "DELAY=50000" and "EXITCODE=21". The 3rd program recovers these values from envp, reports these values along with its pid, then goes to sleep for the specified number of microseconds and then exits using the error code.

d. The main program should generate random delays in microseconds for each child process. These values should range from 1 to 3 million. This means that the 3 children could finish in any order. After launching the 3rd child have the main program loop and wait for each of the children, and print out the pid and exit status of each child. (2)

Part 2: Signals -

In a single program create and test the following signal handlers.

1) Write your program that when it begins it stores the current time using gettimeofday in microseconds since the EPOCH. Write and test a signal handler for SIGINT that prints out the elapsed time since the program began.

2) When you send the program the signal SIGURG use popen to run a shell command that counts the number of processes running on the system - a combination of ps and wc. Read in the result - keeping in mind that you will need to adjust the result by subtracting 1 for the column headers.

3) In sigDemo5 we demonstrated that the system function sent a SIGCHILD interrupt to the parent program. Demonstrate that popen does the same. Insert sleep commands and sleep function calls in your code to determine when the signal is sent. When is this signal sent? Justify your answer.

a) when popen starts to run the command
b) when popen finishes running the command
c) when when pclose is executed.

4) A common use of SIGHUP is to reinitialize a program. For example, to modify Apache's parameter's while it is still running, a systems manager might modify the file apache.conf and then send it a SIGHUP interrupt signal

a) When your program is sent a SIGHUP close all open files (not including stdin, stdout and stderr) using the first and last recorded file descriptor #. (This instruction will make more sense after you read b) and c))

b) Create a file files.list consisting of several file names. When your program is sent a SIGHUP interrupt, read in the list of files and open them, then display the list of open files in /proc/pid/fd. As you are opening them record the 1st and the last file descriptor numbers. (Remember, they open up in order)

c) Modify the list of files. Resend SIGHUP. Verify that the old files are closed and the new files are now opened.

Part 3: Dealing with Different Time Representations.

1) In a single program demonstrate the use of time functions dealing with the time of day.

a) Use the data structure struct tm (see the man pages for strftime and ctime) to create a variable and initialize the fields so that it represents the day you were born. Play close attention to the year field or you might not be born for another 1800 years!!! If you don't know the time of day you were born, call your mom if she's available (tell her you need to know it for an assignment) or make up your own time. (1)

b) Use mktime to convert this time to seconds since the epoch and print out the result. Use ctime, and asctime to print out the result as string. (1)

c) Use strftime to create a string and print out your birthday using at least 6 time related format codes. The output should preserve the day, month, year and hour that you were born but can be presented in any order. The format codes for this are identical to the Unix date command.

Repeat using a different format with the information in a different order.

d) Use gmtime to convert the time to Grenwich Mean Time and then print it out. How many hours difference is there? - write the answer in pen next to your code. (1)

e) Write function addTime(struct tm * anyTime, int months)

i) Now use the 1st format to write out when your birthday will be for the first 10 years of your life.

ii) Reopen or rewind the file. Read in the times one line at a time and use strptime with your first format to decode the string to a struct tm, then print out the result using your 2nd format string.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92784525

Have any Question?


Related Questions in C/C++

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As