Subject Computer Science C-Family Programming


This exercise must be done in the C programming language under Linux.
Using the provided file named main.c, implement the function
create (char* program, char** arglist) such that it does the following.
1. Fork a new process.
2. The parent process returns.
3. The child process executes program with arglist using a system call from the exec family.
    When the call fails, use the errno variable to print an error message and abort the execution.
    The program execution should look like:
barbeau$ ./exercise02
total 100
drwxr-xr-x   2 root root 4096 Sep 6 00:18 bin
drwxr-xr-x   3 root root 4096 Sep 6 13:46 boot
drwxrwxr-x   2 root root 4096 Apr 26 2015 cdrom
*** No such file or directory
Normal main program termination

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>

/* create a child process running a new program
   program=name of the program to run
   arg_list=argument list, a NULL-terminated list of character strings   

void create(char* program, char** arg_list) {
    /* put your code here */
    pid_t pid;
    // 1. Fork a new process....

This is only a preview of the solution. Please use the purchase button to see the entire solution


or free if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats