I'm trying to say to Bash , wait for a Process Start / Begin. I'm trying by this way for example:
notepad=`pidof notepad.exe`
until [ $notepad > 0 ]
do
taskset -p 03 $notepad
renice -n 5 -p $notepad
sleep 5
renice -n 0 -p $notepad
done
well i have the follow questions:
why this generate a file called “0″ (the file are empty) i dont wanna make a new file , just wait for the PID to check execution.
This is a Loop , but if the 2 commands are execute correclty , 1 time how i can continue to done ???
For this its better use "until or while" ???
Another ideas for wait Process Start or Begin ???
There are multiple issues with your code:
>
has to be escaped in [ ]
otherwise your code is equivalent to [ $notepad ] > 0
, directing to a file.>
isn't even the right operator. You wanted -gt
, but as mentioned in point #1 and #2, you shouldn't compare numbers.until
runs the loop until the condition is true. it doesn't wait for the condition to become true, and then run the loop.This is how you should do it:
# Wait for notepad to start
until pids=$(pidof notepad)
do
sleep 1
done
# Notepad has now started.
# There could be multiple notepad processes, so loop over the pids
for pid in $pids
do
taskset -p 03 $pid
renice -n 5 -p $pid
sleep 5
renice -n 0 -p $pid
done
# The notepad process(es) have now been handled
To answer your first question: '>' is not the mathematical/comparison operator 'greater than'; it's bash's way of letting you pipe output to a file (handle).
echo "some text" > myfile.txt
will create a file named myfile.txt, and '>' sent the output of the command into that file. I would imagine that your file '0' has the pid in it, and nothing else.
Instead, try -gt
(or related variants: -ge
, -lt
, -le
, -eg
, -ne
) to test if one value is greater than (or: greater than or equal, less than, less than or equal, equal, not equal, respectively) to see if that helps. That is,
until [ $notepad -gt 0 ]
If I understand correctly, you want to wait until notepad is launched. Then the pidof must be inside your loop.
while ! pidof notepad.exe >> /dev/null ;
do
sleep 1
done
notepad=$(pidof notepad.exe)
taskset -p 03 $notepad
renice -n 5 -p $notepad
sleep 5
renice -n 0 -p $notepad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With