Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-18-2004, 12:25 AM   #1
Registered: Oct 2003
Location: Croatia
Distribution: Fedora 4
Posts: 46

Rep: Reputation: 15
limit program's time and memory

Hi !

Few of my friends and me are going to organize a little programming competition. I'm looking for a way to write a simple grader in c/c++. It should be as simple as to execute the program ( perhaps using the shell("./program.exe") ) and changing the input file ( cp input.in1, check the output.out if there is a correct number, then cp input.in2 and so on. )
I might be able to do that, but I don't know how to limit the program's run time and memory space ( to let's say 1 Mb ). For time I can use "time ./program.exe", but I would like that program is terimnated if it passes the timelimit.

Hope you got what I want to say, and thanks in advance.
Old 03-18-2004, 01:48 AM   #2
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Check the 'ulimit' command.
Old 03-18-2004, 02:33 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 233Reputation: 233Reputation: 233
time limit?
look at you watch, press control-c?

sleep $(( mins * 60 ))    &&    killall -TERM progname &
Old 03-18-2004, 08:52 AM   #4
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
You are going to want to use the setrlimit and getrlimit function calls, you can do a
'man setrlimit' to learn more about them. Keep in mind the ulimit
function call is obsolete and not supported by glibc anymore,
you should use setrlimit/getrlimit pair now on. On the other hand, the ulimit
bash command
is still valid.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Process memory limit Costea Linux - Security 9 09-24-2006 01:42 PM
How to limit memory for users/groups? rubendarioportillo Linux - Newbie 1 09-30-2005 12:35 AM
How to measure a program's peak memory consumption? hae Linux - Software 2 06-23-2005 08:39 AM
Shared memory size limit? nodger Programming 1 03-16-2005 08:28 AM
linux memory limit? rex67 Linux - General 9 01-08-2005 03:36 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration