-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupershell.c
More file actions
51 lines (33 loc) · 764 Bytes
/
supershell.c
File metadata and controls
51 lines (33 loc) · 764 Bytes
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
47
48
49
50
51
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
int main(void)
{
pid_t pid;
pid = fork();
while(pid != 0){
wait(NULL);
pid = fork();
}
char * buffer = malloc(1024);
size_t len = 1024;
char d[] = " \n";
if(pid == 0){
while(1){
printf("$ ");
getline(&buffer , &len , stdin);
// buffer[strcspn(buffer, "\n")] = 0;
char * portion = strtok(buffer,d);
char * portion2 = strtok(NULL,d);
printf("%s\n",portion);
char *argv[] = {portion,portion2,NULL};
execvp(argv[0], argv);
}
}
return (0);
}