simple shell

Hi everyone

I am writing a simple shell but the background '&' not working i dont understand

this is my fork

        pid_t pid;
        pid=fork\(\);


        if\(pid<0\)
            \{
            printf\("\\nChild process failed."\);
            exit\(1\);
            \}
        else if\(pid==0\)
            \{
                if\(execvp\(argv[0],argv\)<0\)
                \{
                    
                printf\("command not found.\\n"\);
                exit\(1\);
                \}
            \}
        
                            
                            
        else if\(background==1\)
            \{    
                pid = waitpid\(pid, NULL, 1\);
                                  if \(pid > 0\)
                                    printf\("working %d\\n", pid\);

            \}

and this is my seaching key '&' code

printf("");
gets(inputBuffer);

            strcpy\(history[j\+\+],inputBuffer\);
            parse\(inputBuffer,argv\);
            if \(strcmp\(argv[0], "exit"\) == 0\)
            exit\(0\);
            
            zzz=strchr\(inputBuffer,'&'\);
            if\(zzz!=NULL\)\{
                    
                    background=1;
                    
                    \}
            else \{
                    background=0;
                    
                    \}

who help me ?

i guess your script was not so simple after all :wink: can you post the stdout and stderr

To keep the forums high quality for all users, please take the time to format your posts correctly.

  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags and by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote