1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Rep Power

    Desperate in need of Assignment help

    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    #include <unistd.h>
    #include <stdlib.h>
    #define LINE_MAX 255
    #define ARG_MAX  10
    #define SH_PROMPT "next> "
    int run_command(char *[]);
    //int getline(char *);
    void parse_line(char *, char*[]);
    int main(void)
    	char line[LINE_MAX+1];
    	char *argbuf[ARG_MAX+1];
    	int temp;
    		printf(SH_PROMPT); fflush(stdout);
    		if ((temp = getline(&line, stdin)) != -1){
    			parse_line(line, argbuf);
    	} while (temp != -1);
    	return 0;
    int run_command(char *command[]){
    	pid_t child;
    	pid_t c;
    	if ((child = fork()) == 0){
    		execvp(command[0], command);
    		fprintf(stderr, "Child process could not do execvp.\n");
    		if(child == (pid_t)(-1)){
    			fprintf(stderr, "Fork failed - Use spoon. \n");
    		else {
    			c = wait(NULL);
    			return 0;
    Write a program that takes a list of command line arguments, each of which is a full path of a command (such as /bin/ls, /bin/ps, /bin/date, /usr/bin/who, /bin/uname etc). Assume the number of such commands is N, your program would then create N child processes, each of which executing one of the N commands. You should make sure that these N commands are executed concurrently, not sequentially one after the other. The parent process should be waiting for each child process to terminate. When a child process terminates, the parent process should print one line on the standard output stating that the relevant command has completed successfully or not successfully (such as "Command /bin/who has completed successfully"). Once all of its child processes have terminated, the parent process should print "All done, bye-bye!" before it itself terminates.

    I have try to code but I don't think it is complete and meet the question requirement. Please help me in finishing it. Please.... Please.... Please!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    Cross-posted here http://stackoverflow.com/questions/1...te-any-command

    > I have try to code but I don't think it is complete and meet the question requirement.
    Original code copied from here http://www.albany.edu/~csi402/pdfs/handout_14.5.pdf

    Now, try again and post what YOU can do, not what your google-fu managed to pull out of the ether.

    Comments on this post

    • pflick agrees : OMG, I can't believe you caught that and can't believe he actually tried to baboozle you. Awesome.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo