Initial setup
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
// PID 1
|
||||
|
||||
int console = open("/dev/console", O_RDWR);
|
||||
|
||||
if (console < 0)
|
||||
{
|
||||
perror("open /dev/console");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dup2(console, STDIN_FILENO);
|
||||
dup2(console, STDOUT_FILENO);
|
||||
dup2(console, STDERR_FILENO);
|
||||
|
||||
close(console);
|
||||
|
||||
while (true)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
|
||||
if (pid == 0)
|
||||
{
|
||||
execl("/bin/sh", "sh", nullptr);
|
||||
perror("exec");
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
if (pid > 0)
|
||||
{
|
||||
waitpid(pid, nullptr, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user