Sharing

2013年4月30日 星期二

I/O status of Process


http://kmaiti.blogspot.tw/2011/09/what-is-wchan-attribute-at-ps-alwww-on.html
http://askubuntu.com/questions/19442/what-is-the-waiting-channel-of-a-process

root@pjack-VirtualBox:~$ ps -alwww
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000   707   706  0  80   0 -  7014 wait   pts/7    00:00:00 bash
0 S  1000  2271   707  0  80   0 - 11950 poll_s pts/7    00:00:00 ssh
0 S  1000 25352 25248  0  80   0 -  4449 poll_s pts/6    00:00:00 tmux
0 S  1000 27179 27178  0  80   0 -  7012 wait   pts/4    00:00:00 bash
0 S  1000 27376 27179  0  80   0 - 10397 poll_s pts/4    00:00:00 ssh
4 R     0 27934 29703  0  80   0 -  3484 -      pts/5    00:00:00 ps
0 S  1000 29430 29429  0  80   0 -  7010 wait   pts/5    00:00:00 bash
4 S     0 29692 29430  0  80   0 - 15074 poll_s pts/5    00:00:00 sudo
4 S     0 29703 29692  0  80   0 -  6991 wait   pts/5    00:00:00 bash
0 S  1000 32224 32220  0  80   0 -  7056 n_tty_ pts/3    00:00:00 bash

root@pjack-VirtualBox:~$ cat /proc/707/wchan
do_wait
root@pjack-VirtualBox:~$ cat /proc/29692/wchan
poll_schedule_timeout

poll_schedule_timeout <= 等 I/O

Perl 學習手冊第六版筆記(一)

Chapter 2 Scalar Data

Single-Quoted String Literals

  • 不轉換 \n\t等空格字元
  • 不轉換 $var 變數
  • 支持多行輸入

Double-Quoted String Literals

  • 支持 backslash escapes
  • 支持 variable interpolated
  • 不支持多行輸入, 用 "\n" 來控制斷行

\n Newline
\r Return
\t Tab
\f Formfeed
\b Backspace
\a Bell
\e Escape(ASCII escape character)
\007 Any octal ASCII value (here, 007= bell)
\x7f Any hex ASCII value (here, 7f= delete)
\x{2744} Any hex Unicode code point (here, U+2744= snowflake)
\cC A “control” character (here, Ctrl-C)
\\ Backslash
\” Double quote
\l Lowercase next letter
\L Lowercase all following letters until \E
\u Uppercase next letter
\U Uppercase all following letters until \E
\Q Quote nonword characters by adding a backslash until \E
\E End \L, \U, or \Q


Comparison Operators

Comparison Numeric String
Equal == eq
Not equal != ne
Less than < lt
Greater than > gt
Less than or equal to <= le
Greater than or equal to >= ge

Boolean Values

Because the string '0' is the exact same scalar, value as the number 0, Perl has to treat them both the same. That means that the string '0' is the only non-empty string that is false.

以下這段程式碼會印 false
if ("0"){
    print 'true'
} else {
    print 'false'
}

$still_true = !! 'Fred';    # return True Boolean value
$still_false = !! '0';      # return False Boolean value


Chapter 3 Lists and Arrays


The qw Shortcut

qw stands for “quoted words” or “quoted by white space”. Either way, Perl treats it like a single-quoted string. Perl actually lets you choose any punctuation character as the delimiter.

qw( fred barney betty wilma dino )
qw! fred barney betty wilma dino !
qw/ fred barney betty wilma dino /

The splice Operator

# second argument: start point
@array = qw( pebbles dino fred barney betty );
@removed = splice @array, 2; # remove everything after fred
                             # @removed is qw(fred barney betty)
                            # @array is qw(pebbles dino)

# third argument: length
@array = qw( pebbles dino fred barney betty );
@removed = splice @array, 1, 2; # remove dino, fred
                                # @removed is qw(dino fred)
                                # @array is qw(pebbles barney betty)

# fourth argument: replacement list
@array = qw( pebbles dino fred barney betty );
@removed = splice @array, 1, 2, qw(wilma); # remove dino, fred
                                           # @removed is qw(dino fred)
                                           # @array is qw(pebbles wilma barney betty)
                                           
                                           
# special case for length = 0, insert the list into original array 
@array = qw( pebbles dino fred barney betty );
@removed = splice @array, 1, 0, qw(wilma); # remove nothing
                                           # @removed is qw()
                                           # @array is qw(pebbles wilma dino fred barney betty

The each Operator

Every time that you call each on an array, it returns two values for the next element in
the array—the index of the value and the value itself

@rocks = qw/ bedrock slate rubble granite /;
while( my( $index, $value ) = each @rocks ) {
    say "$index: $value";
}

Scalar Context

$fred = something;
$fred[3] = something;
123 + something
something + 654
if (something) { ... }
while (something) { ... }
$fred[something] = something;

List Context

@fred = something;
($fred, $barney) = something;
($fred) = something;
push @fred, something;
foreach $fred (something) { ... }
sort something
reverse something
print something

Forcing Scalar Context

@rocks = qw( talc quartz jade obsidian );
print "How many rocks do you have?\n";
print "I have ", @rocks, " rocks!\n";
# WRONG, prints names of rocks
print "I have ", scalar @rocks, " rocks!\n"; # Correct, gives a number


@food  = ("apples", "pears", "eels");
print @food,"\n";             # By itself, print out "applespearseels"
print "@food","\n";           # Embedded in double quotes, print out "apples pears eels"
print @food."\n";             # In a scalar context, print out "3"

my($num) = @_;    # list context, same as ($num) = @_, get the first paramter
my $num = @_;     # scalar context, same as $num = @_, get the number of paramters

2013年4月21日 星期日

Perl 學習手冊第六版筆記(零)




老實說, 才剛開始看 Perl, 我就開始懐念起 Python 的 Principle, 但偏偏工作需求又不得不學

一個是語言學家發明的, 一個是數學家發明的,  一個語言用來形容 "漂亮“ 這件事可能會有數十種以上的說法, 而 Perl 也繼承了這樣的特性,TMTOWTDI, ”There is More Than One Way To Do It" 正是他的中心思想, 但對我來說, 我希望我寫的 code 別人看的懂, 更希望十年後回頭看我寫的 code 還看的懂!所以這樣的特性實在不是我欣賞的, 這或者也和個性有關吧~ 一板一眼的人可能比較喜歡 Python 這樣比較單一的用法. 而且 Perl 有一些用法真的是很沒有系統,也很不直覺, 看一看很容易就忘了@@