Professional Documents
Culture Documents
Experiment 7: Avi Ajmera N203 MBA Tech CS (A) 70471118003
Experiment 7: Avi Ajmera N203 MBA Tech CS (A) 70471118003
Avi Ajmera
N203
MBA Tech CS(A)
70471118003
int main()
{
int fd1,fd2,j;
char b[50];
read(0,b,50);
printf("The string entered through channel 0 is: %s",b);
return 0;
}
int main()
{
char b[] ="DATA WRITTEN THROUGH CHANNEL 1:";
write(1,b,35);
return 0;
}
Program no. 3: Write a program for read through channel 0 and write through channel 1.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
int main()
{
char a[50];
printf("ENTER STRING:");
read(0,a,35);
write(1,a,35);
return 0;
}
int main()
{
printf("Hello before execl\n");
execl("/bin/date","date",NULL);
printf("Hello after execl\n");
return 0;
}
Program no. 6: Write a program to implement fork and execl system call.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
int main()
{
int i;
printf("Hello before execl\n");
i=fork();
if(i==0)
{
printf("In child process\n");
execl("/bin/date","date",NULL);
printf("Hello after fork and execl\n");
}
return 0;
}
Program no. 7: Write a program to implement dup system call.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
int main()
{
int fd1,fd2;
char b[]="Output on screen using fd= 5\n";
fd1=dup(1);
close(1);
write(fd1,b,30);
return 0;
}
REDIRECTIONS:
int main()
{
char inbuf[MSGSIZE];
int p[2], i;
if (pipe(p) < 0)
exit(1);
write(p[1], msg1, MSGSIZE);
write(p[1], msg2, MSGSIZE);
write(p[1], msg3, MSGSIZE);