Solved

Unix system calls

Posted on 2003-10-21
3
268 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 79
Named range not carried over 10 62
ASCII Non-Printable characters/codes and their HTML equivalents 6 106
fix34  challenge 9 105
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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

28 Experts available now in Live!

Get 1:1 Help Now