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
What does it mean for something to be thread-safe? By saying that X is thread-safe, we mean that if multiple threads use X at the same time, we don't have to worry about concurrenc

Locality of reference entails that the page reference being made by a process  Locality of reference entails that the page reference being made by a process is similarly to be

What is Demand paging? Virtual memory is commonly executed by demand paging. In demand paging, the pager brings only those essential pages into memory instead of swapping in a

Gang Scheduling : A set of related process is scheduled to execute on a set of processors at the similar time, on a 1-to-1 basis. Closely related processes or threads may be sched

The performance of a file system depends upon the cache hit rate (fraction of blocks found in the cache). If it takes 1 msec to satisfy a request from the cache, but 40 msec to sat

Question : a) Describe the difference between the authentication of a user account on a peer to peer network and a client server network. b) Compare an end user account with

What are the steps followed in testing? i. Unit testing - The individual components are tested in this type of testing. ii. Module testing - Related collection of independen

how fat file system is organised

NEXT FIT ALGORITHM Here scanning starts from the first fit position and then it finds the next position which is large sufficient to hold the process. Thus the name next fit.

You have a system with two primary workloads. One performs sequential access to a set of large files, the other performs small, independent, random reads to a separate set of large