Reputation: 8173
Hello every one I want to ask a question that what is "simple exec" I have heard it some where and I have searched for it but don't get any useful answer can any one tell me
Thanks in advance
Upvotes: 0
Views: 1215
Reputation: 1715
There are exec functions in all programming languages. These are methods used to invoke the system shell/cmd in from a program.
exec functions are dangerous since they are directly interacting with the OS from external.
Upvotes: 0
Reputation: 2634
An exec system call replaces your current running process with some program stored in disk. It only keeps the system segment of the original process (meaning: PID, file descriptors, and other system stuff) It is provided by the Linux/Unix kernel and there are several ways to call it, check the various exec definitions according to POSIX in http://pubs.opengroup.org/onlinepubs/009604499/functions/exec.html. A simple demostration program would be:
#include <unistd.h>
#include <stdio.h>
int main()
{
printf("Giving control to ls!\n");
execl("/usr/bin/ls","ls",NULL);
printf("This should never be printed..\n");
return 0;
}
That program prints a line and executes 'ls', so you would see the message, then the output of ls, and that's it. The last line isn't displayed because your process was replaced.
Upvotes: 2