User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,101 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,143 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 181 | Replies: 5
Reply
Join Date: May 2008
Posts: 8
Reputation: gogoc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gogoc gogoc is offline Offline
Newbie Poster

How to restrict a program in time consumed

  #1  
May 19th, 2008
can we force a c++ program to end after a certain amount of time
i want to force my program to quit after a certain amount of time so that it would not go on for ever.....
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,332
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: How to restrict a program in time consumed

  #2  
May 19th, 2008
Yes.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: May 2007
Location: Ireland
Posts: 1,751
Reputation: twomers will become famous soon enough twomers will become famous soon enough 
Rep Power: 6
Solved Threads: 33
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: How to restrict a program in time consumed

  #3  
May 19th, 2008
Probably a good idea.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote  
Join Date: May 2008
Posts: 8
Reputation: gogoc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gogoc gogoc is offline Offline
Newbie Poster

Re: How to restrict a program in time consumed

  #4  
May 19th, 2008
thanks for the quick reply
how can we do that??
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,197
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 932
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: How to restrict a program in time consumed

  #5  
May 19th, 2008
use the time() function if you only want accuracy to the second, of clock() for milliseconds.
const time_t MaxTime = 60*60; // one minute timer
time_t t1 = time(0); // start the timer
bool done = false;
while( !done )
{
    time_t t2 = time(0); // get current time
    if( (t2-t1) >= maxtime)
        done = true;
    // do some processing here
}

Or you could create another thread that does the timer stuff. When time is expired the timer thread tells the main thread to quit.
Last edited by Ancient Dragon : May 19th, 2008 at 1:49 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: May 2008
Posts: 8
Reputation: gogoc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gogoc gogoc is offline Offline
Newbie Poster

Re: How to restrict a program in time consumed

  #6  
May 19th, 2008
thanks Dragon i will check it out and then revert back to u
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:44 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC