SlideShare a Scribd company logo
1 of 2
Write a simple timer program. The program will accept a number of seconds as a command line
argument, and steadily count down to 0, decreasing the counter once every second. Echoing
should be turned off as the program runs, and should be turned back on once the program exits.
If the user hits Ctrl-C, the timer will pause/unpause. If the user hits Ctrl-, the program turns
echoing back on then terminates.
Synopsis:
./st seconds
where seconds is an integer indicating the beginning of the countdown.
Sample Usages:
./st 30 causes the timer to count down from 30 to 0
./st prints synopsis
Ctrl-C causes the timer to pause/unpause
Ctrl- causes the program to exit gracefully and ensure that echoing is turned back on.
Hints:
man 3 sleep - use this to make your program wait a second
man 7 signal
spinlock - use this to pause your program. continue can be helpful with this.
if( paused ) continue;
fflush - use this to ensure your output gets to the screen
You may need to turn echoing on, print the seconds, then turn echoing back off.
Solution
Perl prorgram for count down is given below:
#!/usr/bin/perl
use warnings;
use strict;
my $timeCounter = 30;
while($timeCounter > 0){
print("$timeCounter ");
# count down
$timeCounter--;
# pause program for 1 second
sleep(1);
if($timeCounter == 0){
print("Time count zero ");
}
}

More Related Content

Similar to Write a simple timer program- The program will accept a number of seco.docx

Microfluidic Characterization Project Presentation
Microfluidic Characterization Project PresentationMicrofluidic Characterization Project Presentation
Microfluidic Characterization Project Presentation
Yuval Levental
 
N tech flowatch_manual
N tech flowatch_manualN tech flowatch_manual
N tech flowatch_manual
Agus Witono
 

Similar to Write a simple timer program- The program will accept a number of seco.docx (20)

The timer use
The timer useThe timer use
The timer use
 
Microfluidic Characterization Project Presentation
Microfluidic Characterization Project PresentationMicrofluidic Characterization Project Presentation
Microfluidic Characterization Project Presentation
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
While-For-loop in python used in college
While-For-loop in python used in collegeWhile-For-loop in python used in college
While-For-loop in python used in college
 
While_for_loop presententationin first year students
While_for_loop presententationin first year studentsWhile_for_loop presententationin first year students
While_for_loop presententationin first year students
 
Project two c++ tutorial
Project two c++ tutorialProject two c++ tutorial
Project two c++ tutorial
 
Lecture_05_Design_of_Mechatronics_Systems_03.pdf
Lecture_05_Design_of_Mechatronics_Systems_03.pdfLecture_05_Design_of_Mechatronics_Systems_03.pdf
Lecture_05_Design_of_Mechatronics_Systems_03.pdf
 
Introduction to algorithms
Introduction to algorithmsIntroduction to algorithms
Introduction to algorithms
 
NortQ 9021 Manual
NortQ  9021 ManualNortQ  9021 Manual
NortQ 9021 Manual
 
N tech flowatch_manual
N tech flowatch_manualN tech flowatch_manual
N tech flowatch_manual
 
Csd01
Csd01Csd01
Csd01
 
Workshop diy 3 d printing makerbots 2012
Workshop diy 3 d printing   makerbots 2012Workshop diy 3 d printing   makerbots 2012
Workshop diy 3 d printing makerbots 2012
 
Oracle pl sql
Oracle pl sqlOracle pl sql
Oracle pl sql
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16
 
ES-CH5.ppt
ES-CH5.pptES-CH5.ppt
ES-CH5.ppt
 
Keypoints manual
Keypoints manualKeypoints manual
Keypoints manual
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Fadal Diagnostics Maintenance Manual
Fadal Diagnostics Maintenance ManualFadal Diagnostics Maintenance Manual
Fadal Diagnostics Maintenance Manual
 
Leadleds Brand Remote led sign board manual
Leadleds Brand Remote led sign board manualLeadleds Brand Remote led sign board manual
Leadleds Brand Remote led sign board manual
 
Chapter 3 Easy Programming Makes Better Project
Chapter 3  Easy Programming Makes Better ProjectChapter 3  Easy Programming Makes Better Project
Chapter 3 Easy Programming Makes Better Project
 

More from lez31palka

CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docxCSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
lez31palka
 

More from lez31palka (20)

ctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docxctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
ctivity-Based Product Costing 2oberts Company produces two weed eaters.docx
 
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docxCSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
CSC 3020 Introduction to Cybersecurity Lab Assignment 2 CAE-CD Knowled.docx
 
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docxCritical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
Critical Thinking Questions- 18 (page 761) The U-S- government has shu.docx
 
Critical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docxCritical Reflection 2 is a reflective essay that connects a personal e.docx
Critical Reflection 2 is a reflective essay that connects a personal e.docx
 
Credit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docxCredit rating agencies help investor to determine- A- If stock worth t.docx
Credit rating agencies help investor to determine- A- If stock worth t.docx
 
Create software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docxCreate software that can encrypt and decrypt using a general substitut.docx
Create software that can encrypt and decrypt using a general substitut.docx
 
create a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docxcreate a training to give to others on a skillset you are an expert on.docx
create a training to give to others on a skillset you are an expert on.docx
 
Create a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docxCreate a tic tac toe game using Swift and taking input text input- You.docx
Create a tic tac toe game using Swift and taking input text input- You.docx
 
Create a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docxCreate a shell script file called q4-sh.docx
Create a shell script file called q4-sh.docx
 
Create a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docxCreate a python zork file based on the following UML- Use command func.docx
Create a python zork file based on the following UML- Use command func.docx
 
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docxCreate a new python program- sniff_spoof_icmp-py- The program shall sn.docx
Create a new python program- sniff_spoof_icmp-py- The program shall sn.docx
 
Create a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docxCreate a new webpage called -activity2-html-- This new page must inclu.docx
Create a new webpage called -activity2-html-- This new page must inclu.docx
 
Create a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docxCreate a multi-client-single server application to check whether the n.docx
Create a multi-client-single server application to check whether the n.docx
 
Create a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docxCreate a list containing decimal numbers- Write a program to find the.docx
Create a list containing decimal numbers- Write a program to find the.docx
 
Create a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docxCreate a JAVA class called Staff that has the following attributes- St.docx
Create a JAVA class called Staff that has the following attributes- St.docx
 
Create a Java class with the below attributes- Create a class called.docx
Create a Java class with the below attributes-  Create a class called.docxCreate a Java class with the below attributes-  Create a class called.docx
Create a Java class with the below attributes- Create a class called.docx
 
Create a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docxCreate a JAVA class called Faculty that has the following attributes-.docx
Create a JAVA class called Faculty that has the following attributes-.docx
 
Create a garden project - Submit a project scope document - Submit R.docx
Create a garden project   - Submit a project scope document - Submit R.docxCreate a garden project   - Submit a project scope document - Submit R.docx
Create a garden project - Submit a project scope document - Submit R.docx
 
Create a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docxCreate a file named insert-php and add the new records in to your rese.docx
Create a file named insert-php and add the new records in to your rese.docx
 
Corporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docxCorporate Fund started the year with o net asset value of $30-80- By y.docx
Corporate Fund started the year with o net asset value of $30-80- By y.docx
 

Recently uploaded

Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
SaadHumayun7
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
ashishpaul799
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 

Recently uploaded (20)

B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
philosophy and it's principles based on the life
philosophy and it's principles based on the lifephilosophy and it's principles based on the life
philosophy and it's principles based on the life
 
Championnat de France de Tennis de table/
Championnat de France de Tennis de table/Championnat de France de Tennis de table/
Championnat de France de Tennis de table/
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdfPost Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
Post Exam Fun(da) Intra UEM General Quiz 2024 - Prelims q&a.pdf
 
“O BEIJO” EM ARTE .
“O BEIJO” EM ARTE                       .“O BEIJO” EM ARTE                       .
“O BEIJO” EM ARTE .
 
MichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdfMichaelStarkes_UncutGemsProjectSummary.pdf
MichaelStarkes_UncutGemsProjectSummary.pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
Neurulation and the formation of the neural tube
Neurulation and the formation of the neural tubeNeurulation and the formation of the neural tube
Neurulation and the formation of the neural tube
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
ppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyesppt your views.ppt your views of your college in your eyes
ppt your views.ppt your views of your college in your eyes
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
Research Methods in Psychology | Cambridge AS Level | Cambridge Assessment In...
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
An Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptxAn Overview of the Odoo 17 Discuss App.pptx
An Overview of the Odoo 17 Discuss App.pptx
 
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdfTelling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
Telling Your Story_ Simple Steps to Build Your Nonprofit's Brand Webinar.pdf
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 

Write a simple timer program- The program will accept a number of seco.docx

  • 1. Write a simple timer program. The program will accept a number of seconds as a command line argument, and steadily count down to 0, decreasing the counter once every second. Echoing should be turned off as the program runs, and should be turned back on once the program exits. If the user hits Ctrl-C, the timer will pause/unpause. If the user hits Ctrl-, the program turns echoing back on then terminates. Synopsis: ./st seconds where seconds is an integer indicating the beginning of the countdown. Sample Usages: ./st 30 causes the timer to count down from 30 to 0 ./st prints synopsis Ctrl-C causes the timer to pause/unpause Ctrl- causes the program to exit gracefully and ensure that echoing is turned back on. Hints: man 3 sleep - use this to make your program wait a second man 7 signal spinlock - use this to pause your program. continue can be helpful with this. if( paused ) continue; fflush - use this to ensure your output gets to the screen You may need to turn echoing on, print the seconds, then turn echoing back off. Solution
  • 2. Perl prorgram for count down is given below: #!/usr/bin/perl use warnings; use strict; my $timeCounter = 30; while($timeCounter > 0){ print("$timeCounter "); # count down $timeCounter--; # pause program for 1 second sleep(1); if($timeCounter == 0){ print("Time count zero "); } }