I like to run several OpenCV programs one by one in a DO Loop. After searching the web , think for this case need to use batch file. Is that right?
I have 10 OpenCV programs. Each program detect specific features in the image with some successful rate. So, for any image(with many features to be detected) I wonna run first the program with the highest successful rate. If this failed to detect feature then run next one with second highest rate and so on. So, for example program1 is the one with the highest rate, then come program2 and so on
So I have output for each of the 10 OpenCv programs. Let we say output 1 if detect the feature (or the object) in the image and 0 if it failed. So the script should start the program 1 first and if the outcome of this program is 1 then will do something (not important at the moment what), but if the outcome is 0 then need to start the program 2. Same for program 2. If the output of program 2 is 1 then do something (also not important what), but if the output is 0 (means did not detect the object) then run the next program (means program3)
Any idea how it should look like?
I have thinking of something like this , but not sure about the control
#ECHO OFF
START program1.exe
ECHO Timeout waiting for program1.exe to start
GOTO :EOF
:: if the output of program1.exe is 1 then do somethig, else if the output of program1.exe is 0 run the program2.exe (I dont know how this part should be in the script)
:: not sure for control
:startnext
program2.exe
:: or START program2.exe
Related
I am using trace_printk() to print some numbers (they are around a million number). However when I check /sys/kernel/debug/tracing/trace ... only a part of the full range is printed.
Can anyone suggest me how to increase the buffer size or any way to print the full range via any option.
*Note: I don't care about the other output of ftrace.
*Note2: I am kinda beginner in using ftrace and kernel functions.
on Ubuntu 18.04 basis
The buffer_size_kb file exists in the /sys/kernel/debug/tracing directory.
You can make changes through echo.
$ eche echo 4096 > buffer_size_kb
The buffer_size_kb * cpu core count = buffer_total_size_kb is automatically calculated and stored.
This will increase the amount in the ftrace file.
Overwrite file exists in /sys/kernel/debug/tracing/options directory.
Overwrite files can also be changed to echo.
$ eche echo 4096 > buffer_size_kb
The default value is 1, which throws away the oldest event (first part).
Conversely, if zero, discard the most recent event (the back).
In this case, the amount of ftrace files does not increase, and you can see the first or last.
I would like to write a script in batch that forces the computer to enter
sleep (s3) and/or hibernate(s4), for a certain amount of time. I couldn't find answer for this question nowhere.
Example:
Computer enters sleep state.
30 seconds pass.
Computer returns and continues the script.
I managed to use an external program, but after a few cycles of the procedure
the computer for some reason enters a sleep state for 4,294,966,391 seconds
and only continues the script when turned on manually.
Is it possible to make a program written in C to stop and then relaunch itself after x seconds In windows ?? And if yes, how to make it happen ??
You can accomplish that goal by having your program launch a second program, whose only function is to wait a while and then launch your first program again. In pseudocode, the idea would be:
Program A:
Do whatever the program is supposed to do
Launch program B
exit.
Program B:
Wait predetermined time
Launch program A
exit.
I hope this answers your question adequately.
The way I do this kind of thing is with a command-line option 'startDelay=xx'.
If there is no such command, my app just starts up as normal. If there is, its first action , before attempting to open any files, DB, construct GUI, start threads, start server etc. is to sleep for 'xx' seconds.
If my app needs to restart itself, it copies its own command-line, adds the 'startDelay=xx' to it and launches a new copy of itself, which then immediately sleeps. The original then has plenty of time to shut down normally before the new copy starts the bulk of its run-up.
No need for any other app or Windows scheduler and/or cron crap:)
I have written a program which calculates the amount of battery level available in my laptop. I have also defined a threshold value in the program. Whenever the battery level falls below threshold i would like to call another process. I have used system("./invoke.o") where invoke.o is the program that i have to run. I am running a script which runs the battery level checker program for every 5 seconds. Everything is working fine but when i close the bash shell the automatic invocation of invoke.o is not happening. How should i make the invoke.o to be invoked irrespective of whether bash is closed or not??. I am using UBUNTU LINUX
Try running it as: nohup ./myscript.sh, where the nohup command allows you to close the shell without terminating the process.
You could run your script as a cron job. This lets cron set up standard input and output for you, reschedule the job, and it will send you email if it fails.
The alternative is to run a script in the background with all input and output, including standard error output, redirected.
While you could make a proper daemon out of your program that kind of effort is probably not necessary.
man nohup
man upstart
man 2 setsid (more complex, leads to longer trail of breadcrumbs on daemon launching).
is there any nice GNU way how to measure average (worst case, best case) execution time of some command line program? I have image filter, unspecified amount of pictures, filtering them using for-loop in bash. So far I am using time, but I can't find a way how to get some statistics.
You can send the output of time to some file, and then "work" that file
echo "some info" >> timefile.txt
time ( ./yourprog parm1 parm2 ) 2>> timefile.txt
There's an interesting Perl program called dumbbench that's essentially a wrapper around the time command. It runs your program a number of times, throws away outliers, then calculates some statistics.
The author has a couple of articles (here and here) outlining a) why benchmarking sucks, and b) what kind of pretty graphs you can make to make your benchmarking numbers suck a little less.
You're on the right track with time. It's what I use to preform small code execution analyses.
I then use python to collect the statistics by reading the output of time. In order to increase accuracy, I typically do the trial 10 - 1000 times, depending on how long each process takes.
I'm not familiar with any pre-installed GNU application that does this sort of analysis.
#!/bin/bash
for i in {1..100}
do
env time --append -o time_output.txt ./test_program --arguments-to-test-program
done
exit
If you find that the {1..100} syntax doesn't work for you then you should have a look at the seq command.
I used the env time to execute the time program rather than the shell's built in command, which does not take all of the arguments that the time program takes. The time program also takes other arguments to alter the format of it's output, which you will probably want to use to make the data easier to process by another program. The -p (--portability) argument makes it output in the POSIX format (like BASH's builtin time does), but using the -f option you can get more control. man 1 time for more info.
After you have gathered your data a simple perl or python script can easily parse and analyze your timing data.
You should consider whether to time the outer loop and divide by the repetitions rather than timing each iteration separately. If you're worried about discarding the high and low, just do a few more iterations to drown them out.
time for i in {1..1000}
do
something
done
You can capture the output from time in a variable:
foo=$( { time {
echo "stdout test message demo"
for i in {1..30}
do
something
done
echo "stderr test message demo" >&2
} 1>&3 2>&4; } 2>&1 )
and do some fake math:
foo=${foo/.} # "divide" by ...
echo "0.00${foo/#0}" # ... 1000
Or just use bc:
echo "scale=8; $foo/1000" | bc