Skip to content

Commit 48dbe01

Browse files
committed
"How shells start process" section done.
1 parent 2f2fff7 commit 48dbe01

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

ccpp/shell/shell.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,35 @@ char **shell_split_line(char *line)
119119
return tokens;
120120
} /* I definetively should study this function to know exactly how it works, and not just what it does.. :/ */
121121

122-
/* CONTINUE: How shells start processes */
122+
int lsh_launch( char ** args )
123+
{
124+
125+
pid_t pid, wpid;
126+
int status;
127+
128+
pid = fork();
129+
if(pid == 0)
130+
{
131+
if(execvp(args[0], args) == -1) /* take a time after and understand this function */
132+
{
133+
perror("lsh");
134+
}
135+
exit(EXIT_FAILURE);
136+
}
137+
else if(pid <= 0)
138+
{
139+
perror("lsh");
140+
}
141+
else
142+
{
143+
do
144+
{
145+
wpid = waitpid(pid, &status, WUNTRACED);
146+
}
147+
while(!WIFEXISTED(status) && !WIFSIGNALED(status));
148+
}
149+
return 1;
150+
}
151+
152+
153+
/* CONTINUE: SHELL BUILTINS */

0 commit comments

Comments
 (0)