Thread: How to restrict a program in time consumed

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    8

    How to restrict a program in time consumed

    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.....

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It certainly is possible to time your execution.
    Like...

    SAVE START TIME
    PERFORM WORK
    CHECK CURRENT TIME
    SEE IF CURRENT TIME - START TIME EXCEEDS TOTAL TIME
    IF YES EXIT
    IF NO REPEAT FROM PERFORM WORK

    In fact, it might even be possible with just C++ or C libraries.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This is a similar question to the one about how to restrict memory usage.

    If you specify what OS you are using, you can probably get a better answer.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Closed - until the OP learns to provide decent information - see at least two other threads for examples of lack of detail.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple program closing at end, no time to read...
    By Jake.c in forum C Programming
    Replies: 8
    Last Post: 09-08-2008, 02:20 PM
  2. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 02:43 PM
  3. help with basic program
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 02-01-2006, 04:19 PM
  4. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM
  5. worst time to program
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 06-10-2002, 11:32 PM