Professional Documents
Culture Documents
h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#define MAX_COMMAND_LENGTH 25
#define MAX_ARGS 10
char *token;
int i = 0;
args[i++] = token;
args[i] = NULL;
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
exit(EXIT_FAILURE);
} else {
// Parent process
do {
int main() {
char input[MAX_COMMAND_LENGTH];
char *arguments[MAX_ARGS];//ls -l
while (1) {
printf("NARENDRA_SHELL_$ ");
if (strcmp(input, "exit\n") == 0) {
break;
parse_command(input, arguments);
if (strcmp(arguments[0], "cd") == 0) {
if (chdir(arguments[1]) != 0) {
perror("chdir");
} else {
execute_command(arguments);
return 0;