Skip to content
Snippets Groups Projects
Commit b37404c2 authored by mingmingg's avatar mingmingg
Browse files

check

parent 98fbc382
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,11 @@
#include <sys/stat.h>
#include <unistd.h>
#include <linux/limits.h>
#include <io.h>
#include "built_in.h"
#include "signal_handlers.h"
#include "commands.h"
int do_cd(int argc, char** argv) {
if (!validate_cd_argv(argc, argv))
......@@ -36,11 +39,24 @@ int do_fg(int argc, char** argv) {
if (!validate_fg_argv(argc, argv))
return -1;
// TODO: Fill this.
signal(SIGSTOP);
kill(pid,18)
return 0;
}
int do_&(int argc, char** argv){
pid_t pid,buf;
if(!validate_&_argv(argc,argv))
return -1;
buf = process_creation(argv);
if( buf > 0)
pid = buf;
printf("%d",pid);
}
int validate_cd_argv(int argc, char** argv) {
if (argc != 2) return 0;
if (strcmp(argv[0], "cd") != 0) return 0;
......@@ -66,3 +82,13 @@ int validate_fg_argv(int argc, char** argv) {
return 1;
}
int validate_&_argv(int argc, char** argv){
if(argc != 1)
return 0;
if(strcmp(argv[0], "&") != 0)
return 0;
if(access(argv[0],00) == 0)
return 0;
return 1;
}
......@@ -9,7 +9,8 @@
static struct built_in_command built_in_commands[] = {
{ "cd", do_cd, validate_cd_argv },
{ "pwd", do_pwd, validate_pwd_argv },
{ "fg", do_fg, validate_fg_argv }
{ "fg", do_fg, validate_fg_argv },
{ "&", do_&, validate_&_argv }
};
static int is_built_in_command(const char* command_name)
......@@ -28,6 +29,27 @@ static int is_built_in_command(const char* command_name)
/*
* Description: Currently this function only handles single built_in commands. You should modify this structure to launch process and offer pipeline functionality.
*/
int process_creation(struct single_command (*commands)[]){
pid_t pid;
const char path[4096];
strcpy(path,commands);
pid = fork();
if(pid>=0){
if(pid == 0)
execv(path,commands->argv);
return pid;
}else{
printf("Sorry, Fork Failed!");
return -1;
}
}
int evaluate_command(int n_commands, struct single_command (*commands)[512])
{
if (n_commands > 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment