Question: I/O redirection in a C shell. How do implement I/O redirection in a fork-exec() type system call?(any info on I/O redirection helps) if(command)//command holds the

I/O redirection in a C shell.

How do implement I/O redirection in a fork-exec() type system call?(any info on I/O redirection helps)

 if(command)//command holds the system call string { int status; pid_t childpid; switch(childpid = fork()) { case -1: //error printf("Forking error"); return -1; case 0: //child process //pretty sure this is where I/O redirection would occur execl("/bin/sh", "sh", "-c", command, (char*)NULL); default: //parent process waitpid(childpid, &status, WUNTRACED);/ot sure exactly what WUNTRACED IS }//end switch 

}//end if

here is more info on what im doing if this helps

The line is typed in the command line

I/O redirection in a C shell. How do implement I/O redirection in

programname argl arg2 outputfile will execute the program programname with arguments argl and arg2 , the stdin FILE stream replaced by inputfile and the stdout FILE stream replaced by outputfile . For more cases on how redirection I/O redirection should be handled, please visit the textbook website: http://www.tldp.org/LDP/intro- linux/html/sect_05_01 html With output redirection, if the redirection character is > then the outputfile is created if it does not exist and truncated if it does. If the redirection token is >> then outputfile is created if it does not exist and appended to if it does. Note: you can assume that the redirection symbols, & >> will be delimited from other command line arguments by white space - one or more spaces and/or tabs. This condition and the meanings for the redirection symbols outlined above and in the project differ from that for the standard shell IVO redirection is accomplished in the child process immediately after the fork and before the exec command. At this point, the child has inherited all the filehandles of its parent and still has access to a copy of the parent memory. Thus, it will know if redirection is to be performed, and, if it does change the stdin and/or stdout file streams, this will only effect the child not the parent. You can use open to create file descriptors for inputfile and/or outputfile and then use dup or dup2 to replace either the stdin descriptor ( STDIN_FILENO from unistd.h ) or the stdout descriptor STDOUT_FILENO from unistd.h freopen . This function is one of the three functions you can However, the easiest way to do this is to use use to open a standard IVO stream

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!