Ads

Pipe( ) programs

 pipe( ) Programs

1. Write a C program that uses the write() system call to output the string "hello" to the standard output (file descriptor 1), and then prints the number of bytes written.

Specifically, your program should:

- Use the write() function to output the string "hello" to the standard output (file descriptor 1)

- Store the return value of write() in the variable n

- Print the value of n using printf().

2. Write a C program that uses the read() and write() system calls to read input from the standard input (file descriptor 0) and write it to the standard output (file descriptor 1).

Specifically, your program should:

- Use the read() function to read up to 10 bytes from the standard input (file descriptor 0) into the character array b

- Use the write() function to write the read bytes to the standard output (file descriptor 1)

- Print the number of bytes written using `printf(). 

3. Write a C program that demonstrates inter-process communication (IPC) using pipes. The program should:

- Create a pipe using the pipe() system call

- Create a child process using the fork() system call

- In the parent process:

    - Write a message to the pipe using the write() system call

    - Wait for the child process to finish using the wait() system call

- In the child process:

    - Read the message from the pipe using the read() system call

    - Print the received message

Post a Comment

0 Comments