Question


Name: Score:/60 Submit the assignment at the blackboard. The file name should be named as name HW2.c Due date: Friday, 5th of the October 2018 by 11:59 PM 1. Late submission wont be accepted 2. Shared code (except reference code as directed) will bring severe consequence - code scanning will be performed by default. Scenario: You planned to write a program to print out, Working, and then You did a good job!. However, while writing the code, you made a mistake of inserting an infinite loop in the program, func1 as shown below. In order to prevent such possible mistake, you had added an interrupt handler that handles the signal (control+ c) to kill the foreground process and stops the infinite loop. But you have still problems such that your program does not print as planned. When you stop the process, you cannot see You did a good job!. The program and the output after executing the program are as follows. Program #include <signal.h> # include tipi-hdrh void intHandler) f printf This is an interrupt handler)n: exit(EXIT_SUCCESS): void func10 printf(Working!\n): while(1) infinite loop made by mistake* printf Looping... In): sleep(1): void func20O printf( Resumed!\n) exit (EXIT_SUCCESS);
media%2F20f%2F20f4a2b4-89f7-4438-9060-ffNeed help with this please! Linux related!
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

* File: name_HW2.c

* Author: Shravan kumar
*
* Created on 28 September, 2018, 1:17 AM
*/


#include <signal.h>
#include <unistd.h>
#include "tlpi_hdr.h"
#include <setjmp.h>

/* declare variable of type jmp_buf */
jmp_buf resume_here;

void intHandler()
{
printf("This is an interrupt handler\n");
longjmp(resume_here,1);

// Long jmp is used here so that the control goes to setjmp after ctrl +c is entered

exit(EXIT_SUCCESS);   
}


void func1()
{
printf("Working!\n");
while(1)
{/*Infinite loop made by mistake*/

printf("Looping...\n");
sleep(1);

}
}
void func2 ()
{
printf("Resumed!\n");
return; // return statement returns to main function
exit(EXIT_SUCCESS);
  
  
}

int main (int argc, char*argv[])
{
switch (setjmp(resume_here)) // switch case with set jmp is used
{
case 0:
signal(SIGINT,intHandler);
func1();
case 1:
func2();
  
}
printf("You did a good job!");
}   

Output:

Working! Looping- -- Looping--- Looping..- Looping..- This is an interrupt handler You did a good job!

Add a comment
Know the answer?
Add Answer to:
Need help with this please! Linux related! Name: Score:/60 Submit the assignment at the blackboard. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pleas help I need to create and array to add to my code something like this...

    Pleas help I need to create and array to add to my code something like this for (i = 0; i < NUM_THREADS; ++i) { thr_data[i].tid = i; if ((rc = pthread_create(&thr[i], NULL, thr_func, &thr_data[i]))) { fprintf(stderr, "error: pthread_create, rc: %d\n", rc); return EXIT_FAILURE; ::::::::: CODE ::::::::::::: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h>    int sharedVar = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* thread handler */ void *threadHandler(void *vargp) {    int i = 0;    pthread_mutex_lock(&mutex);   ...

  • Design and implement a C version of the color match program. As a starting point, use...

    Design and implement a C version of the color match program. As a starting point, use the file HW2-1-shell.c. The program should employ a reasonable algorithm that compares all pairings of colors in the palette exactly once. A color should not be compared to itself. Nor should two colors be compared to each other more than once. Your C program should print out the total component color difference for the closest pair using the print string provided in the shell...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

  • I need help with the following code... Instructions: This lab builds on the skills from Lab...

    I need help with the following code... Instructions: This lab builds on the skills from Lab 2c, in which you read data values from a file and kept a count of the number of invalid values. In this lab, your program will be using the same code to read each data entry from the file, but you will also save each value in an array named allMags after each is read in. When all values in the file have been...

  • C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include ...

    C LANGUAGE. PLEASE INCLUDE COMMENTS :) >>>>TheCafe V2.c<<<< #include <stdio.h> int main() { int fries; // A flag denoting whether they want fries or not. char bacon; // A character for storing their bacon preference. double cost = 0.0; // The total cost of their meal, initialized to start at 0.0 int choice; // A variable new to version 2, choice is an int that will store the // user's menu choice. It will also serve as our loop control...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • I am needing help with the last part of this code. I have gotten each part...

    I am needing help with the last part of this code. I have gotten each part working correctly accept getting the menu options to work by input and getting to the right section. your help is appreciated. I am to the menu in the code is the display menu and need an loop to interact until they want to exit menu. The edit options only needs an output of "feature is not yet implemented." Due to length I did not...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT