M
mach7sonic
I want to write a C program that randomly writes other C programs,
compiles them, executes them, monitors their progress, and captures
the output. (I'm experimenting with genetic programming). Something
like this:
int main() {
while(1) {
...
// randomly write program to 'file.c'
...
system_command('gcc file.c');
output = system_command('/a.out');
// some sort of threading thing to check if the program is
taking too long, and if so, kill it
}
}
I suspect I'll be writing this on a linux box, but I can work with
Windows code too.
Question 1) How do I execute external programs? (i.e. what is
'system_command'?). What #includes do I need?
Question 2) How do I capture the output of the program?
Question 3) How can I kill a program if it has been running for, say,
x milliseconds? This is basically a question about threads, since
I've never done multithreading in C. I think I'll have to use fork().
Question 4) The program will be writing thousands to millions of
programs. Thus, I'd like the compile-assemble-link process to be as
quick as possible. What is the quickest compiler available? I don't
need the bells and whistles of gcc, just something really fast.
Thanks in advance,
-mach7
compiles them, executes them, monitors their progress, and captures
the output. (I'm experimenting with genetic programming). Something
like this:
int main() {
while(1) {
...
// randomly write program to 'file.c'
...
system_command('gcc file.c');
output = system_command('/a.out');
// some sort of threading thing to check if the program is
taking too long, and if so, kill it
}
}
I suspect I'll be writing this on a linux box, but I can work with
Windows code too.
Question 1) How do I execute external programs? (i.e. what is
'system_command'?). What #includes do I need?
Question 2) How do I capture the output of the program?
Question 3) How can I kill a program if it has been running for, say,
x milliseconds? This is basically a question about threads, since
I've never done multithreading in C. I think I'll have to use fork().
Question 4) The program will be writing thousands to millions of
programs. Thus, I'd like the compile-assemble-link process to be as
quick as possible. What is the quickest compiler available? I don't
need the bells and whistles of gcc, just something really fast.
Thanks in advance,
-mach7