-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.c
46 lines (42 loc) · 821 Bytes
/
cmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "shell.h"
/**
* cmd - UNIX command line interpretor
* @ac : arguments count
* @av : arguments array
* @env : environment array
<<<<<<< HEAD
=======
*
>>>>>>> nick
* Return: 0 if successful; 1 otherwise
*/
int cmd(int ac, char **av, char **env)
{
int wstate;
pid_t parent_pid, child_pid;
if (env[0] == NULL)
{
perror("Env Error");
return (EXIT_FAILURE);
}
parent_pid = getpid();
child_pid = fork();
if (child_pid == -1)
{
perror("Child Error");
return (EXIT_FAILURE);
}
if (child_pid == 0)
{
printf("(%u) A star is born !!\n", parent_pid);
printf("%s", PROMPT);
switch_mode(ac, av, env);
}
else
{
wait(&wstate);
printf("(%u) died for our sins so we could live !!\n", child_pid);
printf("(%u) has left the conversation !!\n", parent_pid);
}
return (EXIT_SUCCESS);
}