반응형
2003 Fall / 컴퓨터 모델링 / 고건 교수님
/**
myshell
zzun
hello82@unitel.co.kr
http://zzun.net
**/
#include <stdio.h>
void fork_and_exec(char* path, int block_parent)
{
int pid;
pid = fork();
if (pid == 0)
execlp(path, path, (char *)0);
else if (pid>0 && block_parent==1)
waitpid(pid, NULL, 0);
}
int main()
{
char buffer[5];
printf("$$");
while (scanf("%s", &buffer) != EOF)
{
if (!strcmp(buffer, "d"))
fork_and_exec("/bin/date", 1);
else if (!strcmp(buffer, "d&"))
fork_and_exec("/bin/date", 0);
else if (!strcmp(buffer, "n"))
fork_and_exec("./myscript", 1);
else if (!strcmp(buffer, "n&"))
fork_and_exec("./myscript", 0);
else
printf("myshell: %s: command not found\n", buffer);
printf("$$");
}
return 0;
}
/**
myshell
zzun
hello82@unitel.co.kr
http://zzun.net
**/
#include <stdio.h>
void fork_and_exec(char* path, int block_parent)
{
int pid;
pid = fork();
if (pid == 0)
execlp(path, path, (char *)0);
else if (pid>0 && block_parent==1)
waitpid(pid, NULL, 0);
}
int main()
{
char buffer[5];
printf("$$");
while (scanf("%s", &buffer) != EOF)
{
if (!strcmp(buffer, "d"))
fork_and_exec("/bin/date", 1);
else if (!strcmp(buffer, "d&"))
fork_and_exec("/bin/date", 0);
else if (!strcmp(buffer, "n"))
fork_and_exec("./myscript", 1);
else if (!strcmp(buffer, "n&"))
fork_and_exec("./myscript", 0);
else
printf("myshell: %s: command not found\n", buffer);
printf("$$");
}
return 0;
}
반응형