start two programs at the same time.
I was looking to start two programs at the same time. Reason & will not work is one needs to run before the other. The first one if using & still will not contuining until it is stopped adn then the next one can start.
So what I am thinking is in a script somehow tell it to start maybe two terminal sessions and then each one run the needed app. Is this called forking or am I off base here. Thanks for any help. Brian1 |
Yes, you will need to fork. If your functionality was written directly in your program, then you could also use threads, but I don't think threading will work for launching external programs.
As far as starting two terminal session, why bother? After your fork, you can start the two programs directly from either a "system" or one of the "exec" family of system calls. However, you cannot use bash scripting, it will not fork. You must use a higher-level language such as perl. python, C, C++ etc... If you don't know how to do this, I could probably whip you up a wrapper in python quite quickly. |
Thanks for the info. time to learn a little more perl. Never tried python before, think it would be a better language to learn.
Thanks Brian1 |
Yeah, I find python considerably easier than Perl. Perl just makes me want to bash my head against the wall...
Also, for clarification, bash will fork, but it will not run forked processes concurrently, so it is of no use to your application here. |
why not?
program1 && program2 & or you can use wait: program1 & wait $! program2 what exactly is the problem/ |
bigearsbilly:
He wants them to run at the _same_ time. Code:
program1 && program2 & Code:
program1 & |
Right.
He hasn't explained the problem clearly. start 2 terminals and run? Code:
xterm -e ksh "ls;sleep 5" |
Try:
Code:
(program1 & sleep 10) ; program2 |
or, if you want a low level efficient solution, why not use C? Here it is:
Code:
#include <stdlib.h> Now, it will run without interpreters or any unnecessary overhead. |
It would help if you Brian1 explain with more details what you want to achieve.
The more I read your initial posting, the less I understand the problem ... |
Thanks for the ideas. What I want to do is either use one command or a click of the mouse to start 2 programs. The issue is the #1 program must be started before #2 program. The problem is if using either & or && does not help with the #1 program. When the #1 program starts it waits for one to press ctrl-c to stop it. It will not allow anything to start in that terminal. I next need to open a 2nd terminal to start the #2 program. #2 program runs it job and then returns back to a command prompt. But #1 must run before #2.
So using the example above program1 && program2 & with not goto the second program because progrma #1 is waiting for one to press ctrl-c to stop it. If ctrl-c ispressed the the #2 program starts but is of no use because #1 has stopped. What this is on is activating the slmodemd program for my winmodem. Once it is running then I can either start kppp or wvdial program. Just wanted one single click to get it all going. This is what I have started with. I can do it with starting 2 scripts but wanted to make it all work in one script. Contents of modemstart. Code:
#!/bin/bash Code:
#!/bin/bash If I could just start slmodemd from the startup it would be great, but anywhere I putting it of course cause the startup to hang because it is waiting for ctrl-c to stop it. Hope this is clearer. I have not checked out python or perl yet. Might have time of the weekend for a crash coarse. Might get a nice book for christmas. Thanks for all your time. Brian1 |
One more solution, write a program and create two threads in it.in each thread using exec call or system command in each of the threads you can run the two programs at the same time.
|
Isn't slmodemd a daemon that runs in the background anyway?
Does this do what you need: Code:
#!/bin/bash |
Quote:
|
No that does not work. once /sbin/slmodemd --alsa is started the rest of that seesion is stalled. As soon as one hits ctrl-C then it will continue. When ctrl-c is pressed that stops the modem driver. So starting kppp is of no use since the modem driver is stopped.
Thanks for the help. Brian1 |
All times are GMT -5. The time now is 11:42 PM. |