A place where I share my daily experience in both technical and non technical issues. Expect to read Linux kernel related posts too.
19 July 2010
Exercising my mind differently (not an "Inception" copy, guys...)
17 January 2010
grep [s]tring anyone?
This is another grep's adventure. It started from a thought: "is there a simple way so that when I grep for something, let's say ps output, grep itself isn't shown there?"
My usual recipe is like below:
$ ps auxw | grep httpd | grep -v grep
But recently I found a neat trick:
$ ps auxw | grep [h]ttpd
Why is that working? Imagine that in the previous command , "ps auxw" would output these two lines among others:
mulyadi 30632 0.0 0.0 5852 1516 pts/8 Ss+ Jan09 0:00 httpd
mulyadi 30950 0.0 0.0 5852 1420 pts/9 Ss+ Jan07 0:00 grep httpd
When you find for httpd, of course both of them will be caught because both of them has "httpd" string. The situation change for the 2nd command:
mulyadi 30632 0.0 0.0 5852 1516 pts/8 Ss+ Jan09 0:00 httpd
mulyadi 30950 0.0 0.0 5852 1420 pts/9 Ss+ Jan07 0:00 grep [h]ttpd
'What, how come?" you say? Recall you invoke "grep [h]ttpd", right? So, that's what displayed in ps. But grep interpret this regular expression differently. It means "I search for httpd", not "[h]ttpd". Everything enclosed in [] is something to search for, unless the "[" or "]" is escaped.
Clever trick I would say.... took me a while to understand it.
20 December 2009
Hopefully these online test results are credible enough to say something about me....
12 December 2009
Contributing to laptop mode tools
As confirmed by laptop mode tools' changelog, my patch is finally merged into their core code. I simply contribute few line to show statistics regarding write and read frequency of every programs recorded during lm-profiler's runtime.
So, how the code looks like?
—- lm-profiler.old2009-06-03 21:12:52.000000000 +0700
+++ lm-profiler2009-06-26 21:08:54.000000000 +0700
@ -209,6 +209,11 @
done
printf ’\r \r’
stop_profiling
+
+echo “Write frequency : ”; cat $WORKDIR/write_accesses_* | sed -e ’s/[ \t]*//;s/[ \t]*$//’ -e ’/$/ d’ | sort | uniq -c | sort -n
+echo “Read frequency : ”; cat $WORKDIR/read_accesses_* | sed -e ’s/[ \t]*//;s/[ \t]*$//’ -e ’/$/ d’ | sort | uniq -c | sort -n
+echo;
+
NETPROFILE=`profilenet`
echo “Profiling run completed.”
Looks awful? I admit it. In short, it grabs files created by lm-profiler during its run time, trims out the blanks and then sort them, while at the same time showing their frequencies ascendingly.NB: Actually it's for my own reminder, but to share with you all. To easily convert text to HTML (and dealing with all those escape characters etc), you could use http://www.textism.com/tools/textile/index.php. Simply paste your text there and click the button, voila..you get the HTML-ized text!
regards,
Mulyadi
25 November 2009
Why so serious? :D
Got this quote from kernelnewbies mailing list....hehehehheheheh :D
"What happens when you read some doc and either it doesn't answer your question or is demonstrably wrong? In Linux, you say "Linux sucks" and go read the code. In Windows/Oracle/etc you say "Windows sucks" and start banging your head against the wall."
-Denis Vlasenko on lkml
PS: s/banging your head*wall/take it for granted/g is better I guess :D I believe many Linux users also bang his/her head when learning Linux for the first time. :))
Moral: just don't bang your head too hard, it hurts, you know? :D
09 November 2009
how to catch white space(s) using grep?
My definition: White space characters are anything that appears as "blank" a.k.a nothing in screen. They include tab, space, carriage return and so on.
As you know, grep provides a way to catch certain characters class or range. Specifically for white spaces, you can use [[:space:]] or [[:blank:]]. Notice the double [[ and ]] !!!
So, suppose you have text file named test.txt that contains:
hehe /var/www/
hehe /var/www2/
ttt hehe /var/www3/
heho /var/www/
Executing:
$ grep ^hehe test.txt
will yield:
hehe /var/www2/
but this:
$ grep -E '^[[:blank:]]*hehe' test.txt
yields:
hehe /var/www/
hehe /var/www2/
In human words, '[[:blank:]]*' will catch zero or more appearance of space or tab before the word "hehe". If you want to catch at least single appearance of any of them, use "+" instead. Oh and let me remind you again, use -E so that "+" doesn't lose its special meaning.
Note: initially, i thought i simply use [:space:] or [:blank:] and end up in something-is-wrong-but-I-dont-know-what land. Turns out, I didn't read the man page carefully (poor me). Since they are built-in classes, I still need to enclose them with another "[" and "]". Valuable experience.....
regards,
Mulyadi.
How to execute multiple commands directly as ssh argument?
Perhaps sometimes you need to do this: ssh user@10.1.2.3 ls It is easy understand the above: run ls after getting into 10.1.2.3 via ssh. Pi...
-
Update: June 14th, 2016 6:01 PM UTC+7: using direct I/O or raw access also bypass filesystem caching. This also has effect to avoid double...
-
Quick summary first: use gcc -save-temps ! Ever dig into Qemu (qemu.org) source code? OK, I assume you ever did that at least once... may ...
-
Ever saw something like below messages inside your KVM (Kernel Virtual Machine) guest's console? " BUG: soft lockup - CPU#0 stuck f...


