mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
42 lines
727 B
C++
42 lines
727 B
C++
#include <sys/wait.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <libmaxsi/platform.h>
|
|
#include <libmaxsi/process.h>
|
|
#include <libmaxsi/thread.h>
|
|
|
|
using namespace Maxsi;
|
|
|
|
int parent(pid_t childid)
|
|
{
|
|
int status;
|
|
waitpid(childid, &status, 0);
|
|
return status;
|
|
}
|
|
|
|
int child()
|
|
{
|
|
const char* programname = "sh";
|
|
const char* newargv[] = { programname };
|
|
|
|
Process::Execute(programname, 1, newargv);
|
|
|
|
return 2;
|
|
}
|
|
|
|
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: fork: %s\n", strerror(errno));
|
|
return 2;
|
|
}
|
|
|
|
return ( childpid == 0 ) ? child() : parent(childpid);
|
|
}
|