Solved

Unix system calls

Posted on 2003-10-21
3
266 Views
Last Modified: 2013-12-26
Hi,

Wonder if anyone can help me out with this.

Using fork(), execlp() and wait() only, how may I write a function in a C program that simulates the shell AND-list behaviour.
And how may I return the exit status of the last shell command executed from this function?

Any clue?
Thanks in advance.
0
Comment
Question by:capricious
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9596693
Hi capricious,

I am sorry but I did not get you

BAsically what feature are u talking abt by saying " the shell AND-list behaviour."



0
 

Author Comment

by:capricious
ID: 9598076
oh, AND-list basically means

$ date && date && ls

and the output prints out the value of 'date', ignoring the rest of the list since date returns 0 as its exit status.

I would like to restrict myself to using the 3 system calls fork(), execlp() and wait() to simulate the AND-list behaviour in a C program. Is this possible?

Thanks for any advice..
0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 50 total points
ID: 9598323
Yes, definitely,

U can use the status parameter in wait() for some particular value which u specify while exiting from child

In child, u can either use a return statement at the end for passing a value OR u can use a exit ( value )

Have a look at the help of wait OR waitpid

Here is one of the links

http://man.he.net/man2/waitpid



 

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now