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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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