Determine the fork and execlp functions - linux, Operating System

Assignment Help:

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.

Related Discussions:- Determine the fork and execlp functions - linux

What are the typical elements of a process image, What are the typical elem...

What are the typical elements of a process image? User data: Modifiable part of user space. May have program data, user stack area, and programs that might be modified. User

Define the server communications module or scm, Define the Server Communica...

Define the Server Communications Module or SCM The Server Communications Module (SCM) performs many necessary functions. The SCM responsible for establishing, maintaining, and

Define properties of distributed operating system, Define properties of Dis...

Define properties of Distributed operating system Distributed:- This system distributes computation among several physical processors. The processors do not share memory or a

Locks - mutexes, Locks (also known as mutexes, short for mutual exclusion l...

Locks (also known as mutexes, short for mutual exclusion locks) provide mutual exclusion to shared data inside a critical session. They are implemented by means of two atomic routi

Explain segmentation and paging, Why are segmentation and paging sometimes ...

Why are segmentation and paging sometimes combined into one scheme? Segmentation and paging are often combined in order to improve upon each other. Segmented paging is helpful

What are kernels and what do kernels do, What are kernels and what do kerne...

What are kernels and what do kernels do? The kernel is a program that comprises the central core of a computer operating   system. It has entire control over everything that

Define caching, Define caching. A cache is a region of fast memory that...

Define caching. A cache is a region of fast memory that holds copies of data. Access to the cached copy is well-organized than access to the original. Caching and buffering are

Copy on write in virtual memory, how copy on write on pages when many proc...

how copy on write on pages when many process works at a same time?

Dynamic scheduling, Dynamic scheduling : The number of thread in a program...

Dynamic scheduling : The number of thread in a program may be changed during the course of operation. Dynamic priority scheduling is a kind of scheduling algorithm in which the pr

Define abbreviation of sstf, SSTF stands for Abbreviation of SSTF is S...

SSTF stands for Abbreviation of SSTF is Shortest-Seek-time-first scheduling

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd