2011-08-27 21:03:39 +00:00
|
|
|
#include <stdio.h>
|
2011-09-21 18:52:29 +00:00
|
|
|
#include <libmaxsi/platform.h>
|
2011-08-27 21:03:39 +00:00
|
|
|
#include <libmaxsi/process.h>
|
2011-09-21 18:52:29 +00:00
|
|
|
#include <libmaxsi/thread.cpp>
|
2011-08-27 21:03:39 +00:00
|
|
|
|
2011-09-21 18:52:29 +00:00
|
|
|
using namespace Maxsi;
|
|
|
|
|
|
|
|
int parent(pid_t childid)
|
2011-08-27 21:03:39 +00:00
|
|
|
{
|
2011-09-21 18:52:29 +00:00
|
|
|
// TODO: wait for child to finish.
|
|
|
|
while ( true ) { Thread::Sleep(100000); }
|
|
|
|
}
|
2011-08-27 21:03:39 +00:00
|
|
|
|
2011-09-21 18:52:29 +00:00
|
|
|
int child()
|
|
|
|
{
|
2011-08-27 21:03:39 +00:00
|
|
|
const char* programname = "sh";
|
|
|
|
const char* newargv[] = { programname };
|
|
|
|
|
2011-09-21 18:52:29 +00:00
|
|
|
Process::Execute(programname, 1, newargv);
|
2011-08-27 21:03:39 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2011-09-21 18:52:29 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
// Reset the terminal's color and the rest of it.
|
|
|
|
printf("\r\e[m\e[J");
|
|
|
|
|
|
|
|
pid_t childpid = Process::Fork();
|
|
|
|
|
|
|
|
if ( childpid < 0 )
|
|
|
|
{
|
|
|
|
printf("init: unable to fork a child\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( childpid == 0 ) ? child() : parent(childpid);
|
|
|
|
}
|