ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hello,
my app needs gnuplot as a backend.someone suggested that i use execve()...
i was reading the man pages and noticed that execve() does not return on success...
i dont know how to use it yet.....my argument is going to be an array of integers....
i dint get what env[] was for?
can someone please explain me how to use this?in a really simple way...
also i want something that returns on sucess cos' i want to display the graph and then continue with my app?
pls help...project due day after...
thanks
dhananjay
You'll need to fork() first. Call execve() in the child process and in the parent process use one of the wait() functions to wait for the child to exit.
More information: You can't pass an array of integers to execve(). It needs to be an array of strings like it says in the man page. You'll need to do some conversion on the array it sounds like.
If you don't want to pass env[] to the program then use execv() instead of exeve().
hey,
thanks for that ....
would you happen to have a snippert of code with both fork() and execve() used....cos i dont know much aboutr these...
thanks
djhananjay
Just so you understand how fork works: Fork creates a copy of your process then returns zero (0) to the child process and returns nonzero (the child's pid) to the parent. This is how all processes are created in Linux (everything forks off of init pretty much).
I thought it was important to put an exit in the child code to prevent zombies. No?
I thought it was important to put an exit in the child code to prevent zombies. No?
Not really in this case anyway:
Code:
DESCRIPTION
The exec family of functions replaces the current process
image with a new process image. The functions described
in this manual page are front-ends for the function
execve(2). (See the manual page for execve for detailed
information about the replacement of the current process.)
Since the process is replaced with the new image, the exit() call is never reached anyway.
Usually, I think it's wait()'ing for the child to exit that reaps the zombies.
Usually, I think it's wait()'ing for the child to exit that reaps the zombies.
My suspicions are confirmed. Here's an excerpt from man wait:
Code:
DESCRIPTION
The wait function suspends execution of the current pro-
cess until a child has exited, or until a signal is deliv-
ered whose action is to terminate the current process or
to call a signal handling function. If a child has
already exited by the time of the call (a so-called "zom-
bie" process), the function returns immediately. Any sys-
tem resources used by the child are freed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.