0% found this document useful (0 votes)
7 views2 pages

As 1

Abcdjsjsnnsnjjjsw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

As 1

Abcdjsjsnnsnjjjsw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<string.h>
#include<sys/wait.h>
int main()
{
char cmd[80], *token, t[10][20];
int pid, ntoken, e;
system("clear");
do
{
printf("MyShell$ ");
gets(cmd);
token=strtok(cmd, " ");
strcpy(t[0], token);
ntoken=0;
while(token)
{
ntoken++;
token=strtok(NULL," ");
if(token!=NULL)
{
strcpy(t[ntoken],token);
}
}
switch(ntoken)
{
case 1:
if(strcasecmp(t[0],"exit")==0)
{
exit(0);
}
else
{
pid=fork();
if(pid==0)
{
e=execlp(t[0],t[0],(char *)0);
if(e<0)
{
printf("Error occured.\n");
}

}
else
{
wait(NULL);
}
}
break;
case 2:
pid=fork();
if(pid==0)
{
e=execlp(t[0],t[0],t[1],(char *)0);
if(e<0)
{
printf("Error Occured\n");
}

}
else
{
wait(NULL);
}
break;
case 3:
pid=fork();
if(pid==0)
{
e=execlp(t[0],t[0],t[1],t[2],(char *)0);
if(e<0)
{
printf("Error Occured\n");
}

}
else
{
wait(NULL);
}
break;
case 4:
pid=fork();
if(pid==0)
{
e=execlp(t[0],t[0],t[1],t[2],t[3],(char
*)0);
if(e<0)
{
printf("Error Occured\n");
}

}
else
{
wait(NULL);
}
break;
}

}
while(1);
return 0;
}

You might also like