Skip to content
Snippets Groups Projects
Commit 29c97447 authored by 김기훈's avatar 김기훈
Browse files

backgroud

parent d4fdef9c
No related branches found
No related tags found
No related merge requests found
......@@ -37,13 +37,20 @@ int do_fg(int argc, char** argv) {
if (!validate_fg_argv(argc, argv))
return -1;
int pid = waitpid(0,0,0);
int pid;
int stat;
if(pid == -1)
printf("Current: no such job\n");
pid = fork();
waitpid(pid, &stat, 0);
if(WIFEXITED(stat))
{
printf("%d done", pid);
}
else
printf("%d done\n", pid);
{
printf("%d running", pid);
}
return 0;
}
......
......@@ -59,31 +59,38 @@ int evaluate_command(int n_commands, struct single_command (*commands)[512])
} else if (strcmp(com->argv[0], "exit") == 0) {
return 1;
}
else {
else
{
pid_t pid;
pid = fork();
switch(pid)
if(pid<0)
printf("FAIL \n");
else if(pid==0)
{
case -1 :
//printf("fail\n");
case 0 :
if(strcmp(com->argv[0], "ls")==0 || strcmp(com->argv[0], "cat")==0)
{
char path[]= "/bin/";
strcat(path, com->argv[0]);
com->argv[0]=path;
execv(com->argv[0], com->argv);
fprintf(stderr, "%s: command not found\n", com->argv[0]);
return -1;
default :
wait((int*)0);
//printf("complete\n");
return -1;
}
else if(strcmp(com->argv[0], "vim")==0)
{
char path[]="/usr/bin/";
strcat(path, com->argv[0]);
com->argv[0]=path;
execv(com->argv[0], com->argv);
}
else
execv(com->argv[0], com->argv);
}
else
wait(&pid);
}
return 0;
}
}
void free_commands(int n_commands, struct single_command (*commands)[512])
{
......
......@@ -12,20 +12,20 @@ int main()
{
char buf[8096];
signal(SIGINT, catch_sigint);
signal(SIGTSTP, catch_sigtstp);
catch_sigint(SIGINT);
catch_sigtstp(SIGTSTP);
while (1) {
fgets(buf, 8096, stdin);
struct single_command commands[512];
struct single_command commands[512]; //argv
int n_commands = 0;
mysh_parse_command(buf, &n_commands, &commands);
int ret = evaluate_command(n_commands, &commands);
free_commands(n_commands, &commands);
n_commands = 0;
n_commands = 0; //argc
if (ret == 1) {
break;
......
......@@ -5,10 +5,11 @@
void catch_sigint(int signalNo)
{
signal(signalNo, SIG_IGN);
return ;
}
void catch_sigtstp(int signalNo)
{
signal(signalNo, SIG_IGN);
return ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment