Skip to content

Conversation

@kevin-sooter
Copy link

No description provided.

Copy link

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (rc < 0)
    { // fork failed; exit
        fprintf(stderr, "fork failed\n");
        exit(1);
    }

Nice!!! Good thinking prepared for even an error.

Copy link

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ex4, you are getting in done Kevin. We will disuss this more in detail tomorrow but we can also accept arguments like this:

int main(int argc, char* argv[])
{
    printf("Parent process here\n");
    int rc = fork();

    if (rc < 0) {
        fprintf(stderr, "fork failed\n");
        exit(1);
    } else if (rc == 0) {
        printf("Child process here\n");

        // execl("/bin/ls", "ls", "-l" (char *) NULL);
        
        // char *args[] = {"ls", "-l", NULL};
        // execv("/bin/ls", args);

        //execlp("ls", "ls", "-l", (char *) NULL);

        char *args[] = {"ls", "-l", NULL};
        execvp("ls", args);
    } else {
        int wc = waitpid(rc, NULL, 0);
    }

    return 0;
}

This way we would then pass "/bin/ls"

@codejoncode
Copy link

The biggest difference is we could replace char *args[] = {"ls", "-l", NULL}; with your char * argv[] main argument (ex4)

Copy link

@codejoncode codejoncode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ex6 Kevin you have fileno(stdout); is what the solution has for this line write(fileno(stdout), NULL, 0); though you may not notice a difference in your output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants