Question

b. Develop a C Application that implements a multithreaded behaviour of the CAT command in LINUX...

b. Develop a C Application that implements a multithreaded behaviour of
the CAT command in LINUX using exec calls. (use of built in CAT command not
allowed.

Homework Answers

Answer #1
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<fcntl.h>
main( int argc,char *argv[3] )
{
int fd,i;
char buf[2];
fd=open(argv[1],O_RDONLY,0777);
if(fd==-argc)
{
printf("file open error");
}
else
{
while((i=read(fd,buf,1))>0)
{
printf("%c",buf[0]);
}
close(fd);
}
}

sample input-output

$gcc –o prgcat.out prgcat.c //outputprogram name and c program name for compilation
same of data using cat on a file
student@ubuntu:~$cat > ff
hello
hai
same output using our program on same file
student@ubuntu:~$./prgcat.out ff
hello
hai
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need...
Client / Server using named pipes with thread and fork() in C/C++ **Note** You will need to write a client program and a server program for this question to be correct. ** **Cannot use socket** client the client application that will get the command from the user and pass the command to be executed from the command line, parses the command and puts a binary representation of the parse into a shared memory segment. At this point, the client will...
Open a new terminal window a) At the command prompt type the “top “command b) Screenshot...
Open a new terminal window a) At the command prompt type the “top “command b) Screenshot and post the number of running processes. c) How many sleeping processes do you have? d) How much total memory is shown? e) How much swap memory is shown? f) Describe what swap memory is and why it is important. g) While using the top command, Press the “h” key. What happens? Press “h” again to return. h) What is the PID of the...
This assignment asks you to develop a basic File Transfer Protocol (FTP) application that transmits files...
This assignment asks you to develop a basic File Transfer Protocol (FTP) application that transmits files between a client and a server using Python.Your programs should implement four FTP commands: (1) change directory(cd), (2) list directory content (ls), (3) copy a file from client to a server (put) and (4) copy a file from a server to a client (get). The project will be completed in two phases. In the first phase, all students will implement two versions of the...
Need this program in Java Develop (using C++ or Java language) the software application described below....
Need this program in Java Develop (using C++ or Java language) the software application described below. Write a program that prints the day number of the year, given the date is in the form month-day-year. For example, if the input is 1-1-09, the day number is 1; if the input is 12-25-09, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4 but not divisible...
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word...
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word " STREET" to the address, for all who live on 2nd or 3rd. For example: "2nd" becomes "2nd STREET" and "3rd" becomes "3rd STREET". Display only the first 9 lines. Hint: Use 2 sed statements with pipes. Task C Display all lines in famous.dat that end in 0 or 1, and have a 1 in the 3rd from the last column. For example lines...
1. An operating system is a. A resource manager b. A user application such as turbo...
1. An operating system is a. A resource manager b. A user application such as turbo t c. A collection of all software packages on the computer d. Another name of my computer including both hardware and software 2. X86 calling convention is about a. How parameters are transferred through stack b. How interrupt vectors are used to find handlers c. How to make a phone call on an x86 computer d. None of the above 3. Paging mechanisms helps...
An important application of regression analysis in accounting is in the estimation of cost. By collecting...
An important application of regression analysis in accounting is in the estimation of cost. By collecting data on volume and cost and using the least squares method to develop an estimated regression equation relating volume and cost, an accountant can estimate the cost associated with a particular manufacturing volume. Consider the following sample of production volumes and total cost data for a manufacturing operation. Production Volume (units) Total Cost ($) 400 4,100 450 5,100 550 5,300 600 5,800 700 6,300...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
(b) Develop the three-week moving average forecasts for this time series. (Round your answers to two...
(b) Develop the three-week moving average forecasts for this time series. (Round your answers to two decimal places.) Week Time Series Value Forecast 1 16 2 11 3 13 4 10 5 14 6 12 Compute MSE. (Round your answer to two decimal places.) MSE = What is the forecast for week 7? (c) Use α = 0.2 to compute the exponential smoothing forecasts for the time series. Week Time Series Value Forecast 1 16 2 11 3 13 4...