Question: IN Linux programming 8) dup(x) duplicates fd[x] in the first empty entry in the fd table. Run following program and explain the output. Assume f1

IN Linux programming

8) dup(x) duplicates fd[x] in the first empty entry in the fd table. Run following program and explain the output. Assume f1 has

hello my boy

x=open("f1", O_RDONLY, 00777);

int y;

y=dup(x);

printf("x:%d y:%d ", x, y);

char buf[50];

int k=read(x, buf, 5);

buf[k]=0;

printf("buf:%s ", buf);

k=read(y, buf, 5);

buf[k]=0;

printf("buf:%s ", buf);

9) (Standard output redirection) Explain the output of the following code.

x=open("f2", O_WRONLY|O_CREAT, 00777);

printf("x:%d ", x);

int y;

close(1);

y=dup(x);

printf("x:%d y:%d ", x, y);

write(1, "hi there", 8);

10) Change the shell such that it can handle standard output redirection.

$ cat f1 > f3

will redirect the output of "cat f1" to file f3.

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!