Programming :: Running Program In Background From Script
Mar 27, 2011
I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes longer than five (5) minutes and this is causing problems when running the rest of the steps in the scripts. Can anyone suggest how to re-program my script. At the moment, the KSH script, i.e. test.ksh, is doing as below:
test.ksh:
.....
.....
xxx/xxx.ksh <--- program/script called by the script
sleep 300
..... run the rest of the script .....
..... problem is sometimes xxx/xxx.ksh takes longer than 300 seconds .....
..... any way that I can monitor that xxx/xxx.ksh finishes before I run .....
..... the rest of the scripts .....
I wonder how one can, if at all, run an X program in the background *in an emulator sub-shell process*. What I mean is to launch a program in an emulator, e.g, by xterm -e gedit
but with gedit (in this example) running in the background from inside the xterm sub-process, so that the xterm will accept other commands. In the above, gedit will run in the foreground, and of course, if you do xterm -e gedit &
then xterm will run in the background, not gedit.In short, I would like to achieve the same thing as "gedit &" as you manually do in xterm, but from another shell. What I aim to do is write an X init script to achieve this result (to have the emulator open and a program or two running from it, in the background, at the X startup).
I think my title pretty much explains it. I am writing a script and I want to start a program in the background, and when that program finishes I want to check the return value to make sure there was no error.For example normal I would do something like this:
#!/bin/sh program if [ ! $? -eq 0 ]; then echo "There was an error" exit 1 fi
Now I want to do something like this:
#!/bin/sh PRTN=`program1 &` program2 if [ ! $? -eq 0 ]; then
[code]....
In this case if program2 finishes before program1, I don't think the return value from program1 $PRTN would be valid at the time it is checked.
I'm trying to figure out how to continue execution of a Python program while a background task is going on.
In bash, it is adding "&" to the end as in:
Code: #! /bin/bash find / -iname "*.py" > /tmp/all_pys & echo "looking for all python scripts and putting them in /tmp/all_pys" (yes, I know I could just put the echo BEFORE the find but I just use it for example)
Say I do that in python (not necessarily running the shell, but perhaps using scriptutil.ffind or something similar), but want to allow the user to be doing something else while running that search in the background, how would I thread, fork, subprocess (not to be confused with the module and Popen) [or whatever I should call it] that?
I am trying to use perl to run a program using the eval command but the program runs infinitely, i just need it to run basically for one second, stop then give me the output. I tried using fork but it does not really work. The child process is not being killed.
my $pid = fork; if ($pid == 0) { my $results = `ngrep etc...`;
I'm looking for a way to detect whether or not a program has been called from pipe, e.g.
Code:
whatever | my_program versus simply just being exectuated directly:
Code:
my_program
Why? In the first case, I want to run the program non-interactively, and in the latter case I want to print out user-friendly messages. I've been thinking along the lines of some check I haven't yet found, like:
I would like to know if there is a linux command to verify the amount of memory used by a program. The programs I am using were compiled with gfortran.
The situation is that I have an MPI-parallel fortran program. I run it and it's distributed on N processors, and each of these processes must call an external program.
This external program is also an MPI program, however I want to run it in serial, on the processor that is calling it, as if it were part of the fortran program. The fortran program waits until the external program has completed, and then continues.
The problem is that this external program seems to run on any processor, and not necessarily the (now idle) processor that called it.
how I can call the program and ensure it runs only on this processor?
Extra information that might be helpful:
If I simply run the external program from the command line (ie, type "/path/myprogram.ex <enter>"), it runs fine. If I run it within the fortran program by calling it via
CALL SYSTEM("/path/myprogram.ex")
it doesn't run at all (doesn't even start) and everything crashes. I don't know why this is.
If I call it using mpiexec:
CALL SYSTEM("mpiexec -n 1 /path/myprogram.ex")
then it does work, but I get the problem that it can go on any node.
My requirement is to save files before shutting the Linux machine down, unattended ie: when the user is not near the machine. This is done whenever the UPS battery is about to die, so that the files get saved. open-Office/text-editor applications that can be saved using keystrokes will have to be found from the running processes and keystrokes should be sent to them from a C program that was started in non-graphics stage. ie: from a C program that forks into memory as a daemon before xwindows part starts. How to I send keystrokes to a running application? (like cotrol + F and then wait and then send next set of keystrokes till the file is saved as a new file or as the same file itself), either from C program or a script?
I have a java program that runs on Debian as a background processor. Yesterday the Java program stopped running. I looked at the memory usage, the system only had 5MB memory left, so my guess is that the java program ran out of memory to use.
However, after we restarted the java program, we could see that the free memory count started to go up. It kept going up from 5MB to over 400MB. The increase of memory happened slowly, when I measured it, I could see that with each minute passing by, there were a bit more memory added into the free memory pool, and meanwhile, the java background process was running.
I wonder why this would ever happen. It's as if our java program first brought the machine done because it consumed all the memories, then after restart, it starts to give back memories.
I frequently run teamviewer on my netbook because it's my favorite remote desktop application, but it doesn't have an option to run at startup nor hidden. This is what I need:o be able to run teamviewer automatically at startup, hidden as a "service?" (meaning no taskbar button nor tray icon) and with a delay of 20 seconds (it has to be started after my wifi has automatically connected, not before).Can't be so hard, but I don't seem to be able to find a good answer to this in Google.
I'm running Utorrent server and I figure I would create an alias to launch the program and run it in the background.alias utorrent='/home/user1/software/utorrent-server-3.0/utserver &'It seems to run the program but the associated webui program is flaky and won't start correctly.If I manually go to the specified path and run the command ./utserver & , I never seem to have an issue with the webui.I was wondering if this could possibly have anything to do with using the '&' ampersand operator in an alias.
Every day I use the top command to check the processes running on my Kubuntu 10.10 system. Every day I find that apt-get is running under the root account and using 100% of the CPU. It'll run forever if I let it but I use "killall" to stop it. Pressing the "c" key in top shows the command used to start the process and doing that I see that apt-get is being started with "apt-get -qq -y update". The -qq param is for quiet mode and the -y is to answer yes to any questions. The important thing is the update parameter. It seems that some "feature" of Ubuntu is starting apt-get in update mode for me on a daily basis. I installed Kubuntu only 3 days ago and I don't recall turning this "feature" on anywhere. How can I disable this "feature" and prevent the system from auto-starting apt-get.?
I have a LAMP server with some php files. When I do this:
> php -f filename.php
It works great. But of course, it stops when I close the SSH window. I need to be able to run it and leave it running. The script is a crawler and it takes about 3 hours to complete it. So I tried this:
> php -f filename.php &
This doesn't work at all. It doesn't even execute the script.
I am running a dual-boot of LMDE and Debian Squeeze XFCE, and I actually have a Debian XFCE question. How can I tell what is running in the background. I have been tweaking my Debian install since I first installed it about 3 weeks ago, and I keep adding to the RAM usage. What is the best way to see what else is running out there and whether or not is it necessary?
Ive got my webserver linked up to my ubuntu computer, and i want it to act like a server controller (for srcds games or w/e) Basically, When i click the start button, the SSH launches 'css.sh' by doing this 'sh css.sh'... Anyway, the .sh file has this inside it cd sourceds/srcds_1/orangebox clear ./srcds_run -console -game cstrike +map de_dust -maxplayers 16 -autoupdate
But either way, that is becides the point. When it launches i dont see the terminal window, its invisible.... (but its running) How do i see it when i go to my ubuntu desktop and how to i put more commands in it once its launched in the background.
In a script that I run manually after I have logged in, I have the following:alias kq='konqueror &' The intention is to run konqueror in the background. What happens is as follows. A. I run kq; it starts konqueror but does not return to the command prompt. I quit konqueror. B. I run kq again ; it starts konqueror and this time I get a the command prompt. If I quit konqueror and run kq for a 3rd time it behaves as in A. Quit and run it behaves as in B, and so on..
I have written a script, lets call it B, that calls scripts A1 to A9. I want to run the A scripts simultaneously since they can take up to 3 hrs to complete. As you might expect, I use the & to run the script in background. I am looking for a mechanism to evaluate the return code from the A scripts when they eventually complete?
How do you move a running process to the background? For example, type the command sleep 60 on the command line and try moving that process to the background.
I'm running Ultimate Edition 2.0 64bit. When I'm running Firefox and I'm not doing anything on it it starts to use the disk intensively. I checked on terminal using the top command and it IS Firefox using up to 85-90% of the resources. Anyone know what the problem is here? Can it be hacked? I already uninstalled and installed back again and it still doing it.