LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-18-2004, 12:25 AM   #1
nibbler
Member
 
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 input.in, check the output.out if there is a correct number, then cp input.in2 input.in 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
itsme86
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
bigearsbilly
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?

dirty?
Code:
sleep $(( mins * 60 ))    &&    killall -TERM progname &
 
Old 03-18-2004, 08:52 AM   #4
jinksys
Member
 
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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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