Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Тестовые примеры / ch8 / test_exec
.C #include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int System( const char *cmd) // emulate the C system function
{
pid_t pid;
int status;
switch (pid=fork())
{
case -1: return -1;
case 0: execl("/bin/sh", "sh", "-c", cmd, 0);
perror("execl");
exit(errno);
}
if (waitpid(pid,&status,0)==pid && WIFEXITED(status))
return WEXITSTATUS(status);
return -1;
}
int main()
{
int rc = 0;
char buf[256];
do
{
printf("sh> "); fflush(stdout);
if (!gets(buf)) break;
rc = System(buf);
} while (!rc);
return (rc);
}
Соседние файлы в папке ch8