Write and test a signal handler for sigint

Assignment Help C/C++ Programming
Reference no: EM131945869

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.

Reference no: EM131945869

Questions Cloud

Design a plan that sallys immediate supervisor can use : She is experiencing a very low level of job satisfaction. Describe two active responses that Sally might undertake due to her dissatisfaction.
Estimate the value of the equilibrium constant : Estimate the value of the equilibrium constant at 610 K for each of the following reactions. ?Gf for BrCl(g) is -1.0 kJ/mol.
What is the cost of equity for blue dog : The Blue Dog Company has common stock outstanding that has a current price of $20 per share, and its next projected dividend is $.50.
Identify the polar and non-polar regions of the structure : Identify the polar and non-polar regions of the structure. How is this an effective cleaner
Write and test a signal handler for sigint : Write and test a signal handler for SIGINT that prints out the elapsed time since the program began. When popen finishes running the command.
Calculate the equivalent annual cost of each alternative : Blooper Industries must replace its magnoosium purification system. Quick & Dirty Systems sells a relatively cheap purification system for $12 million.
How many grams of hydrochloric acid are produced : If excess sulfuric acid reacts with 30.0 g of sodium chloride, how many grams of hydrochloric acid are produced?
What is the present value of the tax savings : Bling enterprises is contemplating the purchase of a $1 million piece of equipment. The equipment is eligible for a CCA rate of 30%, the company's tax rate.
Determine the project should be accepted or not : Blue Note Jazz Productions has decided to cash in on the country craze by starting a subsidiary that will promote concerts by "Country Jazz" artists.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Discuss why naming conventions are important

Why is it important to consistently follow coding rules and techniques? What are the pitfalls of not doing so?

  Show veclist after the following statement executes

Suppose that vecList is a vector container and vecList = {12, 16, 8, 23, 40, 6, 18, 9, 75} Show vecList after the following statement executes:

  A computational study of a spring-mass system in steady

a computational study of a spring-mass system in steady stateidealized spring-mass systems have numerous applications

  Find the average length of the strings in the vector

Write a C++ function: Here is the function you should implement:

  Assessment system of a university

Write a program for Assessment system of a University

  Assignmentthe main purpose of the assignment is to let you

assignmentthe main purpose of the assignment is to let you practice the following programming techniques read data from

  Prepare a program that uses at least two functions that can

prepare a program that uses at least two functions that can be called from your main. this program is a number game

  Create a class named realtorcommission.

Create a class named RealtorCommission. Fields include the sale price of a house, the sales commission rate, and the commission.

  Create functions based on your existing source code

Create functions based on your existing source code (ex. GetCar, CreateCar, CalculateLapTime) which take in the appropriate parameters and give the correct output. Use pointers where applicable.

  Write a complete c++ program

The main program will read in a parameter value n (read this in main). Then it will call a function read2arrays (details below) to read lists of grades into two arrays, which the main program will call test1 and test2 (or some other names of your ..

  Create a text adventure game that uses pointers you have a

create a text adventure game that uses pointers. you have a rich eccentric uncle billy who is soon to be deceased.he

  Identify some of the elements needed in c++

Input and Output are necessary functions with any code - Define I/O and identify some of the elements needed in C++ that would use input or create output.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd