Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Systems744
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
SHREYANSH JAIN
Systems744
Commits
1e0b1296
Commit
1e0b1296
authored
Aug 13, 2019
by
desiredeveloper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reaping children in case of error
parent
dda893a2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
292 additions
and
239 deletions
+292
-239
assignment1/a.out
assignment1/a.out
+0
-0
assignment1/myshell.c
assignment1/myshell.c
+292
-239
No files found.
assignment1/a.out
View file @
1e0b1296
No preview for this file type
assignment1/myshell.c
View file @
1e0b1296
...
...
@@ -6,94 +6,106 @@
#include <time.h>
#include <sys/wait.h>
#define MAX_INPUT_SIZE 1024
#define MAX_TOKEN_SIZE 64
#define MAX_NUM_TOKENS 64
extern
char
**
environ
;
void
funcExit
(){
void
funcExit
()
{
exit
(
0
);
}
void
funcEnv
(){
void
funcEnv
()
{
int
i
;
for
(
i
=
0
;
environ
[
i
]
!=
NULL
;
i
++
)
printf
(
"%s
\n
"
,
environ
[
i
]);
printf
(
"%s
\n
"
,
environ
[
i
]);
}
void
funcClear
(){
void
funcClear
()
{
printf
(
"\e[1;1H\e[2J"
);
}
void
funcDir
(
char
**
tokens
){
char
a
[
150
]
=
"ls -la "
;
system
(
strcat
(
a
,
tokens
[
1
]));
void
funcDir
(
char
**
tokens
)
{
char
a
[
150
]
=
"ls -la "
;
system
(
strcat
(
a
,
tokens
[
1
]));
}
void
funcPwd
(){
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
getcwd
(
temp
,
150
);
printf
(
"%s:$ "
,
temp
);
void
funcPwd
()
{
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
getcwd
(
temp
,
150
);
printf
(
"%s:$ "
,
temp
);
free
(
temp
);
}
void
funcCd
(
char
*
fpath
){
void
funcCd
(
char
*
fpath
)
{
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
getcwd
(
temp
,
150
);
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
getcwd
(
temp
,
150
);
if
(
fpath
&&
chdir
(
fpath
)
!=
0
){
if
(
fpath
&&
chdir
(
fpath
)
!=
0
)
{
printf
(
"ERROR: Directory doesn't exist!
\n
"
);
return
;
}
printf
(
"BEFORE:
\n
OLDPWD=%s
\n
PWD=%s
\n
"
,
getenv
(
"OLDPWD"
),
getenv
(
"PWD"
));
if
(
fpath
){
setenv
(
"OLDPWD"
,
temp
,
1
);
getcwd
(
temp
,
150
);
setenv
(
"PWD"
,
temp
,
1
);
printf
(
"BEFORE:
\n
OLDPWD=%s
\n
PWD=%s
\n
"
,
getenv
(
"OLDPWD"
),
getenv
(
"PWD"
));
if
(
fpath
)
{
setenv
(
"OLDPWD"
,
temp
,
1
);
getcwd
(
temp
,
150
);
setenv
(
"PWD"
,
temp
,
1
);
}
else
setenv
(
"OLDPWD"
,
temp
,
1
);
setenv
(
"OLDPWD"
,
temp
,
1
);
printf
(
"AFTER:
\n
OLDPWD=%s
\n
PWD=%s
\n
"
,
getenv
(
"OLDPWD"
),
getenv
(
"PWD"
));
printf
(
"AFTER:
\n
OLDPWD=%s
\n
PWD=%s
\n
"
,
getenv
(
"OLDPWD"
),
getenv
(
"PWD"
));
free
(
temp
);
}
void
ioRedirect
(
char
**
tokens
,
int
n
){
void
ioRedirect
(
char
**
tokens
,
int
n
)
{
FILE
*
fp
;
char
**
arglist
=
(
char
**
)
malloc
(
MAX_NUM_TOKENS
*
sizeof
(
char
*
));
int
j
=
0
;
int
j
=
0
;
for
(
int
i
=
0
;
strcmp
(
tokens
[
i
],
">>"
)
&&
strcmp
(
tokens
[
i
],
">"
)
&&
strcmp
(
tokens
[
i
],
"<"
);
i
++
){
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
]);
for
(
int
i
=
0
;
strcmp
(
tokens
[
i
],
">>"
)
&&
strcmp
(
tokens
[
i
],
">"
)
&&
strcmp
(
tokens
[
i
],
"<"
);
i
++
)
{
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
switch
(
fork
())
{
switch
(
fork
())
{
case
-
1
:
break
;
case
0
:
if
(
!
strcmp
(
tokens
[
n
-
2
],
">>"
))
fp
=
freopen
(
tokens
[
n
-
1
],
"a"
,
stdout
);
else
if
(
!
strcmp
(
tokens
[
n
-
2
],
">"
))
fp
=
freopen
(
tokens
[
n
-
1
],
"w"
,
stdout
);
if
(
!
strcmp
(
tokens
[
n
-
2
],
">>"
))
fp
=
freopen
(
tokens
[
n
-
1
],
"a"
,
stdout
);
else
if
(
!
strcmp
(
tokens
[
n
-
2
],
">"
))
fp
=
freopen
(
tokens
[
n
-
1
],
"w"
,
stdout
);
else
fp
=
freopen
(
tokens
[
n
-
1
],
"r"
,
stdin
);
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
){
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
execv
(
temp
,
arglist
);
fp
=
freopen
(
tokens
[
n
-
1
],
"r"
,
stdin
);
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==
-
1
)
{
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
)
exit
(
0
);
}
free
(
temp
);
}
wait
(
NULL
);
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
free
(
arglist
[
i
]);
free
(
arglist
);
...
...
@@ -101,146 +113,168 @@ void ioRedirect(char **tokens,int n){
// http://www.linuxquestions.org/questions/programming-9/how-a-father-process-know-which-child-process-send-the-signal-sigchld-266290/
void
handler
(
int
sig
){
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
100
);
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
void
handler
(
int
sig
)
{
char
*
buffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
100
);
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
pid_t
pid
;
pid
=
wait
(
NULL
);
printf
(
"
\n
Background process [%d] finished.
\n
"
,
pid
);
signal
(
SIGCHLD
,
NULL
);
getcwd
(
temp
,
150
);
sprintf
(
buffer
,
"%s:$ "
,
temp
);
write
(
1
,
buffer
,
50
);
getcwd
(
temp
,
150
);
sprintf
(
buffer
,
"%s:$ "
,
temp
);
write
(
1
,
buffer
,
50
);
free
(
temp
);
free
(
buffer
);
}
void
exBackground
(
char
**
tokens
,
int
n
){
void
exBackground
(
char
**
tokens
,
int
n
)
{
char
**
arglist
=
(
char
**
)
malloc
(
MAX_NUM_TOKENS
*
sizeof
(
char
*
));
int
j
=
0
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
){
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&"
)
!=
0
){
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&"
)
!=
0
)
{
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
signal
(
SIGCHLD
,
handler
);
switch
(
fork
())
{
switch
(
fork
())
{
case
-
1
:
break
;
case
0
:
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
){
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
execv
(
temp
,
arglist
);
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==
-
1
)
{
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
)
exit
(
0
);
}
free
(
temp
);
}
j
=
0
;
j
=
0
;
}
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
free
(
arglist
[
i
]);
free
(
arglist
);
}
void
exSerial
(
char
**
tokens
,
int
n
){
void
exSerial
(
char
**
tokens
,
int
n
)
{
char
**
arglist
=
(
char
**
)
malloc
(
MAX_NUM_TOKENS
*
sizeof
(
char
*
));
int
j
=
0
;
int
j
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
){
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
ioFlag
=
0
;
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&&"
)
!=
0
){
if
(
!
ioFlag
)
ioFlag
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
if
(
!
ioFlag
){
switch
(
fork
())
{
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&&"
)
!=
0
)
{
if
(
!
ioFlag
)
ioFlag
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
if
(
!
ioFlag
)
{
switch
(
fork
())
{
case
-
1
:
break
;
case
0
:
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
){
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
execv
(
temp
,
arglist
);
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==
-
1
)
{
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
)
exit
(
0
);
}
free
(
temp
);
}
}
else
{
ioRedirect
(
arglist
,
j
);
else
{
ioRedirect
(
arglist
,
j
);
}
wait
(
NULL
);
j
=
0
;
j
=
0
;
}
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
free
(
arglist
[
i
]);
free
(
arglist
);
}
void
exParallel
(
char
**
tokens
,
int
n
){
void
exParallel
(
char
**
tokens
,
int
n
)
{
char
**
arglist
=
(
char
**
)
malloc
(
MAX_NUM_TOKENS
*
sizeof
(
char
*
));
int
j
=
0
,
forkcalls
=
0
;
int
j
=
0
,
forkcalls
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
){
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
int
ioFlag
=
0
;
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&&&"
)
!=
0
){
if
(
!
ioFlag
)
ioFlag
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
if
(
!
ioFlag
){
while
(
tokens
[
i
]
!=
NULL
&&
strcmp
(
tokens
[
i
],
"&&&"
)
!=
0
)
{
if
(
!
ioFlag
)
ioFlag
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
arglist
[
j
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
arglist
[
j
++
],
tokens
[
i
++
]);
}
arglist
[
j
]
=
NULL
;
char
*
temp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
150
);
if
(
!
ioFlag
)
{
forkcalls
++
;
switch
(
fork
())
{
switch
(
fork
())
{
case
-
1
:
break
;
case
0
:
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
){
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
execv
(
temp
,
arglist
);
strcpy
(
temp
,
"/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==
-
1
)
{
strcpy
(
temp
,
"/usr/bin/"
);
strcat
(
temp
,
arglist
[
0
]);
if
(
execv
(
temp
,
arglist
)
==-
1
)
exit
(
0
);
}
free
(
temp
);
}
}
else
{
ioRedirect
(
arglist
,
j
);
else
{
ioRedirect
(
arglist
,
j
);
}
j
=
0
;
j
=
0
;
}
for
(
int
i
=
0
;
i
<
forkcalls
;
i
++
)
for
(
int
i
=
0
;
i
<
forkcalls
;
i
++
)
wait
(
NULL
);
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
for
(
int
i
=
0
;
arglist
[
i
]
!=
NULL
;
i
++
)
free
(
arglist
[
i
]);
free
(
arglist
);
}
/* Splits the string by space and returns the array of tokens
*/
...
...
@@ -250,118 +284,137 @@ char **tokenize(char *line)
char
*
token
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
int
i
,
tokenIndex
=
0
,
tokenNo
=
0
;
for
(
i
=
0
;
i
<
strlen
(
line
);
i
++
){
for
(
i
=
0
;
i
<
strlen
(
line
);
i
++
)
{
char
readChar
=
line
[
i
];
if
(
readChar
==
' '
||
readChar
==
'\n'
||
readChar
==
'\t'
){
if
(
readChar
==
' '
||
readChar
==
'\n'
||
readChar
==
'\t'
)
{
token
[
tokenIndex
]
=
'\0'
;
if
(
tokenIndex
!=
0
){
tokens
[
tokenNo
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
if
(
tokenIndex
!=
0
)
{
tokens
[
tokenNo
]
=
(
char
*
)
malloc
(
MAX_TOKEN_SIZE
*
sizeof
(
char
));
strcpy
(
tokens
[
tokenNo
++
],
token
);
tokenIndex
=
0
;
}
}
else
{
}
else
{
token
[
tokenIndex
++
]
=
readChar
;
}
}
free
(
token
);
tokens
[
tokenNo
]
=
NULL
;
tokens
[
tokenNo
]
=
NULL
;
return
tokens
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
char
line
[
MAX_INPUT_SIZE
];
char
**
tokens
;
int
i
;
clock_t
t1
;
FILE
*
fp
;
if
(
argc
==
2
)
{
fp
=
fopen
(
argv
[
1
],
"r"
);
if
(
fp
<
0
)
{
FILE
*
fp
;
if
(
argc
==
2
)
{
fp
=
fopen
(
argv
[
1
],
"r"
);
if
(
fp
<
0
)
{
printf
(
"File doesn't exists."
);
return
-
1
;
}
}
while
(
1
)
{
int
parallel
=
0
,
serial
=
0
,
background
=
0
,
io
=
0
,
cdir
=
0
;
while
(
1
)
{
int
parallel
=
0
,
serial
=
0
,
background
=
0
,
io
=
0
,
cdir
=
0
;
/* BEGIN: TAKING INPUT */
bzero
(
line
,
sizeof
(
line
));
if
(
argc
==
2
)
{
// batch mode
if
(
fgets
(
line
,
sizeof
(
line
),
fp
)
==
NULL
)
{
// file reading finished
if
(
argc
==
2
)
{
// batch mode
if
(
fgets
(
line
,
sizeof
(
line
),
fp
)
==
NULL
)
{
// file reading finished
break
;
}
line
[
strlen
(
line
)
-
1
]
=
'\0'
;
}
else
{
// interactive mode
}
else
{
// interactive mode
funcPwd
();
scanf
(
"%[^
\n
]"
,
line
);
getchar
();
}
if
(
!
strlen
(
line
))
if
(
!
strlen
(
line
))
continue
;
/* END: TAKING INPUT */
line
[
strlen
(
line
)]
=
'\n'
;
//terminate with new line
tokens
=
tokenize
(
line
);
for
(
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
){
if
(
!
parallel
)
parallel
=
strcmp
(
tokens
[
i
],
"&&&"
)
==
0
;
for
(
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
)
{
if
(
!
parallel
)
parallel
=
strcmp
(
tokens
[
i
],
"&&&"
)
==
0
;
if
(
!
serial
)
serial
=
strcmp
(
tokens
[
i
],
"&&"
)
==
0
;
if
(
!
serial
)
serial
=
strcmp
(
tokens
[
i
],
"&&"
)
==
0
;
if
(
!
background
)
background
=
strcmp
(
tokens
[
i
],
"&"
)
==
0
;
if
(
!
io
)
io
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
if
(
!
background
)
background
=
strcmp
(
tokens
[
i
],
"&"
)
==
0
;
if
(
!
io
)
io
=
strcmp
(
tokens
[
i
],
">>"
)
==
0
||
strcmp
(
tokens
[
i
],
">"
)
==
0
||
strcmp
(
tokens
[
i
],
"<"
)
==
0
;
}
t1
=
clock
();
if
(
parallel
)
exParallel
(
tokens
,
i
);
else
if
(
serial
)
exSerial
(
tokens
,
i
);
else
if
(
background
)
exBackground
(
tokens
,
i
);
else
if
(
io
)
ioRedirect
(
tokens
,
i
);
else
{
if
(
!
strcmp
(
tokens
[
0
],
"dir"
)
&&
i
==
2
){
if
(
parallel
)
exParallel
(
tokens
,
i
);
else
if
(
serial
)
exSerial
(
tokens
,
i
);
else
if
(
background
)
exBackground
(
tokens
,
i
);
else
if
(
io
)
ioRedirect
(
tokens
,
i
);
else
{
if
(
!
strcmp
(
tokens
[
0
],
"dir"
)
&&
i
==
2
)
{
funcDir
(
tokens
);
}
else
if
(
!
strcmp
(
tokens
[
0
],
"clear"
)){
else
if
(
!
strcmp
(
tokens
[
0
],
"clear"
))
{
funcClear
();
}
else
if
(
!
strcmp
(
tokens
[
0
],
"quit"
)){
else
if
(
!
strcmp
(
tokens
[
0
],
"quit"
))
{
funcExit
();
}
else
if
(
!
strcmp
(
tokens
[
0
],
"env"
)){
else
if
(
!
strcmp
(
tokens
[
0
],
"env"
))
{
funcEnv
();
}
else
if
(
!
strcmp
(
tokens
[
0
],
"cd"
)){
else
if
(
!
strcmp
(
tokens
[
0
],
"cd"
))
{
funcCd
(
tokens
[
1
]);
}
else
{
else
{
system
(
line
);
}
}
t1
=
clock
()
-
t1
;
printf
(
"%f sec
\n
"
,
(
double
)
t1
/
CLOCKS_PER_SEC
);
printf
(
"%f sec
\n
"
,
(
double
)
t1
/
CLOCKS_PER_SEC
);
// Freeing the allocated memory
for
(
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
){
for
(
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
)
{
free
(
tokens
[
i
]);
}
free
(
tokens
);
}
return
0
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment