Does someone know how to integrate a collection of programs as one whole program?
Thanks. :)

Recommended Answers

All 8 Replies

Have one controlling program that can start and kill the others with system calls such as fork() and execve().

When you compile your 'C' code, an object file is generated by the compiler. Such object files from each program(from the collection of programs) are build into a single binary(executabe) file by another program called linker.

So, how does this fork() and execve() work ???
I still haven't heard of that yet..

Thanks for both of our answers. :)

Thanks for both of our answers. :)

i think you can get some help from user defined functions .

Member Avatar for Mouche

fork() and exec*() work together to make a new process. I put a * after exec because there is a group of exec functions such as execl, execvp, and others.

fork():
Fork copies the program completely and the copy continues running the parent program's code starting on the line after fork. fork() returns 0 for the child process (the new one) and returns the child process's process id to the parent.

You might use fork() like this:

int pid;

pid = fork();
if (pid) {
  /* Parent does something here */
} else {
  /* Child does something here */
}

exec*():
The exec functions take a program and load it into the new process, erasing the parent's program.

For example, here is how you would run "ls -l" in the new forked() process:

execl("/bin/ls", "/bin/ls", "-l", (char *) 0);

or ... are you asking how most of unix utilities work?

What appears to be several programs is actually just one program with multiple functionality bundled up, when the program is launched it looks at argv[0] to see what 'program' or functionality to run!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.