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.
I need to run a program (or a script) from within my program, but the second one must stop the caller program from running.
You must imagine, at a specific event a script has to be run from my program, which then continues listening for other events. I dont need to wait for return values or so, I just want to issue a command and then forget about it.
How do I do that? execve will stop my caller program (or at least i understood the manpage so)
A few more details would be helpful but you can do it wiht a simple bash script:
!#bin/bash
cd <path to directory where first executable located>
<name of first exec>
cd <path to script>
./<name of script> &
cd <path to directory where execve located>
execve
Create a text file in your home directory or anywhere you want and give it a nice name like "doexec". Cut and paste the above text to doexec. make sure there is no white space before"!#bin/bash", i.e. these are the first characters in the text file w/o white space in front.
Then open a console su to root and navigate to the location of doexec and run:
# chmod a+x doexec
That makes the script executable. To run doexec, navigate to the directory where it's located and run:
$ ./doexec
Alternatively, you could edit the called script to run the exe program first and shut down at the appropriate time rather than create a new script.
Based on your description, consider system(). While fork() will work, your "calling code" continues to run, which you do not seem to want.
With system() your calling thread is suspened until the child completes.
If you want the calling thread to "become" the child process, execve() and its cousins -- execl, execlp, execle, execv, execvp. These do not return except on error.
system() is probasbly the easiest one code and deal with
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.