Modify HW05 to use signals to pause the output of the timer

Modify HW05 to use signals to pause the output of the timer instead of control characters. So, the only terminal setting you will need to modify programatically is echoing. If the user hits ctrl-C, the program pauses. If they hit it again, it unpauses. Ctrl-\\ terminates and restores the settings gracefully.

Hints :

Spinlocks :

while( pause == true)
{}

If pause is set to true, then this while loop will iterate. When pause gets set to false, this loop gets skipped.

See the attached code for a spinlock example, spinlock.cpp

Spinlock.cpp

HW5

Solution

#include #include #include int main(int ac, char* args[]) { struct termios old_settings, new_settings; // get the terminal settings tcgetattr(0, &old_settings); tcgetattr(0, &new_settings); // update them // turn off echoing new_settings.c_lflag &= ~ECHO; // change VSTART to \'u\' new_settings.c_cc[VSTART] = \'u\'; // change VSTOP to \'p\' new_settings.c_cc[VSTOP] = \'p\'; // send them back tcsetattr(0, TCSANOW, &new_settings); // do the countdown thing int seconds = atoi(args[1]); while(seconds >= 0) { printf(\"%i\ \", seconds); sleep(1); seconds--; } // restore original settings tcsetattr(0, TCSANOW, &old_settings); }
Modify HW05 to use signals to pause the output of the timer instead of control characters. So, the only terminal setting you will need to modify programatically

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site