SlideShare a Scribd company logo
Write a C program called pross.c to implement the UNIX/Linux equivalent shell commands:
ls -al / | grep -i s | tr a-z A-Z
The symbol “|― is the Linux pipe command.
The signature of the main program:
int main (int argc, char *argv[]) {
}
Where:
•  argc is the number of arguments that are passed to the program plus 1
•  argv[0] is the name of the program
A template of the main program and its functions are provided to you along with this document
on Blackboard. Use the following system calls to implement the shell commands:
o  dup2()
o  one of the exec()
o  fork()
o  pipe()
o  close()
pross.c
Solution
In the c programming the shell commands can't be executed directly, but there are several other
options to get implemented.
1. Do not use the shell , but bypass the shell and run the commands driectly with specified
program.Many of the basic utilities can be accessed easily enough and system calls are available
for system programming tasks.You need to use pipe() ,fork () and exec().
2. Use system() to run the command if input and output are not important.
3.use poopen () if control on either input or output is needed.
4. run the shell as a coprocess.
If we select to bypass the shell, it can be bit easier to have buffered.
STDIO functions are available on a file decsriptor with
fdopen- associate a sream with a file descritor
FILE *fdopen(int fd , const char *mode);
after this call, STDIO buffered I/O and standard I/O function such as scanf() and print f() can be
used on fd.
system- run shell command
int system(const char *command);
poopen- open to/from shell
FILE *POPEN(const char *command, const char * type);
int pclose (FILE *stream);
FILE *fp;
char *command;
fp=popen(command,"r");
fscanf(fp,....);
fclose(fp);
fp=open(command ,"w");
fprintf(fp,.....);
fclose(fp);
The shell can be forked off as a child of the program and then commands can be both sent to it
and the results can be read. More generally any other program could be run this way. There are
number of problems with this approach.
1. The practical problem of keeping the process in sync. For instance can you recognizing when
the coprocess has finished responding to given request.
2. the shell is receiving its input through a pipe and not through a terminal , it uses file not line
buffering, It will not receive input until the buffer is full. some solutions to this problems are
override the standard isatty by dynamically linking in a version that always returns true.this will
require altering the environment before calling the child coprocess, so that the child process
dynamic load library path includes the revised ispatty.

More Related Content

PDF
Shell to be modified#include stdlib.h #include unistd.h .pdf
DOCX
httplinux.die.netman3execfork() creates a new process by.docx
PDF
Os lab final
PPTX
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
PDF
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
PDF
Help Needed!UNIX Shell and History Feature This project consists.pdf
DOCX
Program Assignment Process ManagementObjective This program a.docx
PPTX
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Shell to be modified#include stdlib.h #include unistd.h .pdf
httplinux.die.netman3execfork() creates a new process by.docx
Os lab final
System Calls.pptxnsjsnssbhsbbebdbdbshshsbshsbbs
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
Help Needed!UNIX Shell and History Feature This project consists.pdf
Program Assignment Process ManagementObjective This program a.docx
Linux Systems Programming: Inter Process Communication (IPC) using Pipes

Similar to Write a C program called pross-c to implement the UNIX-Linux equivalen.docx (20)

DOCX
OverviewIn this assignment you will write your own shell i.docx
PPTX
Systemcall1
PDF
Tested on ubuntu,Linux#include stdio.h #include string.h.pdf
DOCX
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
DOCX
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
PPT
PIPES in Unix programming in computer science and engineering.PPT
PPTX
Linux Systems Programming: Process CommunCh11 Processes and Signals
PPTX
Operating systems_lab03_part3_pa1_intro.pptx
PPTX
Unit V.pptx
DOCX
BACKGROUND A shell provides a command-line interface for users. I.docx
PDF
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
PDF
Operating System Lecture Notes Mit 6828 Itebooks
PDF
a. Modify the C program ex.9 so that it simulates the Unix pipe comm.pdf
PDF
About linux-english
PPTX
Process (OS),GNU,Introduction to Linux oS
PPT
5.IPC.ppt JSS science and technology university
DOCX
#include string.h#include stdlib.h#include systypes.h.docx
PDF
OverviewIn this assignment you will write your own shell i.docx
Systemcall1
Tested on ubuntu,Linux#include stdio.h #include string.h.pdf
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
1 of 9 CSCE 3600 Systems Programming Major Assignm.docx
PIPES in Unix programming in computer science and engineering.PPT
Linux Systems Programming: Process CommunCh11 Processes and Signals
Operating systems_lab03_part3_pa1_intro.pptx
Unit V.pptx
BACKGROUND A shell provides a command-line interface for users. I.docx
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
Operating System Lecture Notes Mit 6828 Itebooks
a. Modify the C program ex.9 so that it simulates the Unix pipe comm.pdf
About linux-english
Process (OS),GNU,Introduction to Linux oS
5.IPC.ppt JSS science and technology university
#include string.h#include stdlib.h#include systypes.h.docx
Ad

More from SUKHI5 (20)

DOCX
Ghocse the correct answer below- A- No- because the probabafy of burvi.docx
DOCX
Given Data- MAGLIOCHETTI MOVING CORP- Statement of Earni.docx
DOCX
From this table- which mineral level had a significance on which varia.docx
DOCX
Given a ListItem class- complete main() using the built-in list type t.docx
DOCX
Given a -discrete object- O- the notationO means what- Choose all the.docx
DOCX
Give five examples of unsustainable living or actions from your own ev.docx
DOCX
Give an inductive definition of the function rev which takes a list an.docx
DOCX
Give feedback19 lines (16 sloc) 450 Bytes.docx
DOCX
Give a big-Oh characterization- in terms of n- of the running time of.docx
DOCX
Give at least 2 reasons why an entire population of microbes does not.docx
DOCX
Giovani Photography bills $650 to Diane Fenning for photography servic.docx
DOCX
Germ Theory was a framework that--- All of these argued that disease w.docx
DOCX
General Knowledge- In 1927 The Jazz Singer- starring Al Jolson- was hi.docx
DOCX
Gereldo recently won a lottery and chose to receive $70-000 todsy inst.docx
DOCX
genomes are usually circular loops of double-stranded deoxyribonucleic.docx
DOCX
Gastrointestinal Disorders- Teaching about Increasing Fiber Intake- pl.docx
DOCX
Geert Hofstede surveyed more than 116-000 IBM employees in 40 countrie.docx
DOCX
Gale- Mctean- and Lux are partners of Burgers and Brew Company with ca.docx
DOCX
Future valuesFor the case shown in the following table- calculate the.docx
DOCX
Function Name- isOneCapital Input- 1- (char) A letter 2- (char) A lett.docx
Ghocse the correct answer below- A- No- because the probabafy of burvi.docx
Given Data- MAGLIOCHETTI MOVING CORP- Statement of Earni.docx
From this table- which mineral level had a significance on which varia.docx
Given a ListItem class- complete main() using the built-in list type t.docx
Given a -discrete object- O- the notationO means what- Choose all the.docx
Give five examples of unsustainable living or actions from your own ev.docx
Give an inductive definition of the function rev which takes a list an.docx
Give feedback19 lines (16 sloc) 450 Bytes.docx
Give a big-Oh characterization- in terms of n- of the running time of.docx
Give at least 2 reasons why an entire population of microbes does not.docx
Giovani Photography bills $650 to Diane Fenning for photography servic.docx
Germ Theory was a framework that--- All of these argued that disease w.docx
General Knowledge- In 1927 The Jazz Singer- starring Al Jolson- was hi.docx
Gereldo recently won a lottery and chose to receive $70-000 todsy inst.docx
genomes are usually circular loops of double-stranded deoxyribonucleic.docx
Gastrointestinal Disorders- Teaching about Increasing Fiber Intake- pl.docx
Geert Hofstede surveyed more than 116-000 IBM employees in 40 countrie.docx
Gale- Mctean- and Lux are partners of Burgers and Brew Company with ca.docx
Future valuesFor the case shown in the following table- calculate the.docx
Function Name- isOneCapital Input- 1- (char) A letter 2- (char) A lett.docx
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Insiders guide to clinical Medicine.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Institutional Correction lecture only . . .
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharma ospi slides which help in ospi learning
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Microbial disease of the cardiovascular and lymphatic systems
Insiders guide to clinical Medicine.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
VCE English Exam - Section C Student Revision Booklet
Institutional Correction lecture only . . .
Renaissance Architecture: A Journey from Faith to Humanism
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
RMMM.pdf make it easy to upload and study
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharma ospi slides which help in ospi learning
Mark Klimek Lecture Notes_240423 revision books _173037.pdf

Write a C program called pross-c to implement the UNIX-Linux equivalen.docx

  • 1. Write a C program called pross.c to implement the UNIX/Linux equivalent shell commands: ls -al / | grep -i s | tr a-z A-Z The symbol “|― is the Linux pipe command. The signature of the main program: int main (int argc, char *argv[]) { } Where: •  argc is the number of arguments that are passed to the program plus 1 •  argv[0] is the name of the program A template of the main program and its functions are provided to you along with this document on Blackboard. Use the following system calls to implement the shell commands: o  dup2() o  one of the exec() o  fork() o  pipe() o  close() pross.c Solution In the c programming the shell commands can't be executed directly, but there are several other options to get implemented. 1. Do not use the shell , but bypass the shell and run the commands driectly with specified program.Many of the basic utilities can be accessed easily enough and system calls are available for system programming tasks.You need to use pipe() ,fork () and exec(). 2. Use system() to run the command if input and output are not important. 3.use poopen () if control on either input or output is needed. 4. run the shell as a coprocess. If we select to bypass the shell, it can be bit easier to have buffered.
  • 2. STDIO functions are available on a file decsriptor with fdopen- associate a sream with a file descritor FILE *fdopen(int fd , const char *mode); after this call, STDIO buffered I/O and standard I/O function such as scanf() and print f() can be used on fd. system- run shell command int system(const char *command); poopen- open to/from shell FILE *POPEN(const char *command, const char * type); int pclose (FILE *stream); FILE *fp; char *command; fp=popen(command,"r"); fscanf(fp,....); fclose(fp); fp=open(command ,"w"); fprintf(fp,.....); fclose(fp); The shell can be forked off as a child of the program and then commands can be both sent to it and the results can be read. More generally any other program could be run this way. There are number of problems with this approach. 1. The practical problem of keeping the process in sync. For instance can you recognizing when the coprocess has finished responding to given request. 2. the shell is receiving its input through a pipe and not through a terminal , it uses file not line buffering, It will not receive input until the buffer is full. some solutions to this problems are
  • 3. override the standard isatty by dynamically linking in a version that always returns true.this will require altering the environment before calling the child coprocess, so that the child process dynamic load library path includes the revised ispatty.