All pastes #113121 Raw Edit

fork gahhhh

public text v1 · immutable
·published 2006-08-03 11:32 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/wait.h>

int main()
{
	
	char **newargv;
	char *temp;
	char command[100];
	extern char **environ;
	newargv = malloc(sizeof(char)*2);
    
	printf("\n****** My shell starts here ******\n");
	printf("\n**********************************\n");
	printf("myBash$> ");

	/*Read command and other agruments from stdin*/	
	
	while(fgets(command,100,stdin) != NULL && (printf("myBash$> ") != -1))
	{	
	   pid_t child;
	   
		temp = (newargv[0] = strtok(command," \t\n"));
	
		child = fork();
		
		if(temp != NULL)
		{
			/*if input is exit*/
			if(!strcmp("exit",newargv[0]))
			{
				free(newargv);
				exit(0);
			}
			
			if(child == 0)
			{
			  execve("/bin/ls",newargv,environ);
			}
		}
   }
 free(newargv);
 
 return 0;
}