control the execution of the scripts
How to control the execution of the scripts based on time and memory constraints?
How to find out the time and memory requirement of a script? I have a script which should execute after a previous script finishes execution. How can i know that a script will be finished in particular time so that i can use this information to start the next script? |
The time requirements will vary, the memory requirements may or may not vary depending on the programme you've written. You can use 'time' to work out how long your programme took to run (I think it's just "time ./programme", but I'd need to check when I get home).
If you wanted to run one script then the other, however, then you could just run: Code:
./script1; ./script2 Hope this helps, |
well how can you ever expect to know when a script is going to finish? That does't sound like a reasonable thing to ever hope to know outside of your own experience of how the script works.
Scripts don't wait for others to finish, they are executed sequentially, that's how scripts work. when one line of code has executed, the next one runs. The script has no implicit idea how long it's taking to do anything. |
You might use the time command before the script
Code:
time myscript.sh |
Wrong end of the problem...
prravin1,
Most of the other answers illustrate excellent intentions, but a basic misunderstanding about how true multithreaded, multiuser, multitasking operating systems work. The one that recommended "script1 ; script2" was the only correct answer. While you can time ONE EXECUTION of a script, there is nothing in the script, shell, or kernel that ensures that it will EVER AGAIN execute in exactly the same time. The "most correct" way to ensure this has been one of these methods: 1. execute them sequentially, as the command line provided. 2. Use semaphore controls, a shared memory or file-system flag that can be turned on or off. Have the first script ensure that it is off when it starts, start the second script a few seconds later. The second script loops, checking for the flag to be ON before continuing to run. Have the first script turn the flag ON as it exits, this signals the second script to run. Let the second script turn the flag back OFF as it exits. The easy way for a non-programmer to implement this is by using a simple file (perhaps under /tmp or /var/tmp) with a unique name, and test on it exists, or it does not. This uses the characteristics of the system and plays to its strengths, rather than trying to force it into a predictable mode not natural to this kind of system. ----------- Late addition: you CAN force a system to be a bit more predictable by running the REAL TIME kernel. The overhead it adds makes your maximum performance somewhat less, but it ensures that most processes and calls have a MUCH HIGHER chance of completing in about the same time EVERY time. While very useful for some things, the better answer is to make your scripts EVENT controlled (and event controlling) rather than leaving things at the mercy of load and clock. I hope that this helps. Please feel free to question if I have left anything unclear. |
Perhaps the simplest way to do this is to create one script that simply executes each of the other programs in turn, as child processes to itself, waiting patiently for each one to complete.
|
Quote:
Quote:
Code:
> setsid ./myscript1.sh |
Quote:
|
a flag is whatever you want it to be. Normally you'd "touch" a file in one script and look for it in another, but there is no formal way to do this at all.
|
You can set an exit status (a number that you'd prefer) in the bash script (an example here) or you could do something like this:
Code:
echo "finished" > /dev/shm/script1status Code:
cat /dev/shm/script1status |
Quote:
Can you show it using an example code? |
script1:
Code:
... Code:
... |
Script execution
Simple framework, and I have not tested this code so take it for what it is.
Script one Code:
#!/bin//bash Code:
#!/bin/bash |
All times are GMT -5. The time now is 02:22 PM. |