Determine the fork and execlp functions - linux, Operating System

Assignment

  • What I'm covering:
  • General control flow
  • fork()
  • execlp()
  • Parameters
  • Makefiles
  • Additional Questions

General Control Flow/fork()

  • In the Controller:

int main(int argc,char** argv){

.....

for(i = 0;i < 4;i++){

int ret_pid = fork();

if ( ret_pid < 0 ) exit(1); //this means fork() failed

else if ( ret_pid == 0 ) !  //this is the child

else ...  //this is the parent (Controller)

}

return 0;

}

 

execlp()

  • This function call has a lot of gotchas that look very confusing at first glance.
  • The first argument to execlp is the string with the file name that will be executed...and so is the second.
  • Think about your own program being called from the command-line ( > ./a.out arg1 arg2 ). In this case, the value of argv[0] in the program is "a.out".

Same thing applies when using exec, you just have to be explicit about it.

 

More execlp() and parameters

  • The rest of the parameters to execlp are strings containing the rest of the arguments, in our case, the numbers that the calculator will be operating on.
  • These will be passed to Controller as arguments, and from there, they will be passed to Calculator.
  • No matter what, the last argument to execlp MUST be a null-terminator (NULL or (char*) 0).

This is because the argument list must be null-terminated, just like any other string.

 

Makefiles

  • This assignment requires that TWO executables be created: the Controller and the Calculator.
  • Because of how Eclipse generates its makefiles, if you try to do this in a single project, Eclipse will whine. I recommend doing your coding in a normal text editor (gedit, emacs, vi, bluefish, etc.), and writing your own makefile.
  • There are plenty of makefile tutorials online; but this project (and the next one) will not require a particularly complex makefile.

 

Makefile example

  • Here's the general format of a makefile entry:

[target] : [dependency1] ! [dependencyn] [command to execute]

  • In this example, when you call make target, the make program checks if any of the dependencies of target are out of date.
  • If one or more of them is out of date, the command to execute is run.
Posted Date: 3/4/2013 6:41:52 AM | Location : United States







Related Discussions:- Determine the fork and execlp functions - linux, Assignment Help, Ask Question on Determine the fork and execlp functions - linux, Get Answer, Expert's Help, Determine the fork and execlp functions - linux Discussions

Write discussion on Determine the fork and execlp functions - linux
Your posts are moderated
Related Questions
Problem 1. What is kernel? What are the main components of a kernel? Defining Kernel Explaining Main components of Kernel 2. What is mutual exclusion? What are i

Q. Suppose that you want to utilize a paging algorithm that requires a reference bit (such as second-chance replacement or working-set model) however the hardware does not provide

The idea of reference counting is to maintain, for every object, the total number of references to that object, i.e. the number of "incoming" pointers. Whenever the number of refer

Define lazy swapper. Rather than swapping the entire process into main memory, a lazy swapper is used. A lazy swapper never swaps a page into memory unless that page will be ne

What do you mean by semaphore?  Semaphore : A synchronization variable that acquires on positive integer values. Invented by the Dijkstra P (semaphore): an atomic proce

Define logical address and physical address. An address formed by the CPU is referred as logical address. An address seen by the memory unit that is the single loaded into the

Q. How does DMA raise system concurrency? How does it make difficult hardware design? Answer: DMA increases system concurrency by allowing the CPU to perform tasks while the

what is secondary storage management

Q. Why do some systems stay track of the type of a file while others leave it to the user or simply don't implement multiple file types? Which system is "better?" Answer: A f

What is the information associated with an open file? Various pieces of information are associated with  an open file which may be: File pointer Disk location of th