Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by rwniceing
at 2024-08-31 00:35:26
Point:500 Replies:9 POST_ID:829209USER_ID:12079
Topic:
Linux;;Apache Web Server
1- Could I use 2e8 for 200000000 for linux script ?
2- and I try the similar for loop in php, c,c++ and asp that is okay
no any memory allocation error.
But when run it on linux shell on my VPS server apache centos6, it came out error, Why ?
#./for
./for: xmalloc: cannot allocate 9 bytes (1873698816 bytes allocated)
How to solve this out
for file
--------------
2- and I try the similar for loop in php, c,c++ and asp that is okay
no any memory allocation error.
But when run it on linux shell on my VPS server apache centos6, it came out error, Why ?
#./for
./for: xmalloc: cannot allocate 9 bytes (1873698816 bytes allocated)
How to solve this out
for file
--------------
#!/bin/bashfor i in {1..200000000}do a=1234+5678+ib=1234*5678+ic=1234/2+i#echo $idone 1:2:3:4:5:6:7:8:
Expert: ozo replied at 2024-08-31 19:21:07
I think
for ((i=1;i<=$[bc 2*10^6];i++))
would have to be
for ((i=1;i<=$(echo "2*10^6"|bc);i++))
But that would cause an echo process and a bc process to be forked 2*10^6 times, so you probably wouldn't want to do it that way.
for ((i=1;i<=$[bc 2*10^6];i++))
would have to be
for ((i=1;i<=$(echo "2*10^6"|bc);i++))
But that would cause an echo process and a bc process to be forked 2*10^6 times, so you probably wouldn't want to do it that way.
Author: rwniceing replied at 2024-08-31 02:39:15
Now it works for question-1 with bc command and question-2
#!/bin/bashfor ((i=1;i<=$[bc 2*10^6];i++))doa="$[1234+$5678+$i]"b="$[1234*5678+$i]"c="$[1234/2+$i]"#echo Welcome $idoneecho $a=$b=$c 1:2:3:4:5:6:7:8:9:
Thanks for your reply and the code need to be checked for other value
Assisted Solution
Expert: gheist replied at 2024-08-31 02:27:35
200 points EXCELLENT
You cannot use 2e8
It is more like ${bc 2*10^8)
It is more like ${bc 2*10^8)
Author: rwniceing replied at 2024-08-31 02:21:17
question-2 is solved by ozo after change for loop,for (( i=1; i<=200000000; ++i )); and the memory
allocation error is gone.
and it is interesting the memory usage for that for syntax is different from "for i in (1 ..200000000)" that won't use back the memory from previous i, instead, it will create many copy until memory reach to the limit before i= 200000000.
And it seems solving question-1 needs more time
allocation error is gone.
and it is interesting the memory usage for that for syntax is different from "for i in (1 ..200000000)" that won't use back the memory from previous i, instead, it will create many copy until memory reach to the limit before i= 200000000.
And it seems solving question-1 needs more time
Expert: gheist replied at 2024-08-31 01:57:37
sysctl vm.overcommit_memory=1 >> /etc/sysctl.conf
will allow to allocate memory lazy way so it is not really allocated unless accessed.
will allow to allocate memory lazy way so it is not really allocated unless accessed.
Author: rwniceing replied at 2024-08-31 01:56:23
This two sites may assist the question-1 for nature log with bc command for 2e8
http://advantage-bash.blogspot.hk/2012/03/logarithm-and-anti-logarithm.htmlhttp://www.linuxfromscratch.org/blfs/view/7.4/general/bc.html
http://advantage-bash.blogspot.hk/2012/03/logarithm-and-anti-logarithm.htmlhttp://www.linuxfromscratch.org/blfs/view/7.4/general/bc.html
Accepted Solution
Expert: ozo replied at 2024-08-31 01:11:19
300 points EXCELLENT
I'm not sure if you'd call this a short hand
e=`yes | head | tr -c 0 0`
for (( i=1; i<=2${e::8}; ++i )); do echo $i ; done
or
e=2$(for e in {1..8}; do echo -n 0 ; done)
for (( i=1; i<=$e; ++i )); do echo $i ; done
or
for (( i=1; i<=2$(yes 0 | head -8|tr -cd 0); ++i )); do echo $i ; done
e=`yes | head | tr -c 0 0`
for (( i=1; i<=2${e::8}; ++i )); do echo $i ; done
or
e=2$(for e in {1..8}; do echo -n 0 ; done)
for (( i=1; i<=$e; ++i )); do echo $i ; done
or
for (( i=1; i<=2$(yes 0 | head -8|tr -cd 0); ++i )); do echo $i ; done
Author: rwniceing replied at 2024-08-31 00:51:05
no short hand writing for 200000000 ?
Expert: ozo replied at 2024-08-31 00:49:22
{1..200000000} will attempt to expand the entire list of 200000000 white space separated numbers
it would be much more memory efficient to use something like
for (( i=1; i<=200000000; ++i ));
it would be much more memory efficient to use something like
for (( i=1; i<=200000000; ++i ));