2014年3月28日金曜日

date command ミリ秒 ms

date command ミリ秒 ms

$ echo  $(date +%c) $(printf '%03d' $(expr `date +%N` / 1000000))

処理に時間を掛けたくない場合は, simpleにする.
date +"%Y%m%d %H:%M:%S.%N"

terminalを閉じてもprocessを終了せず継続実行.

$ nohup command &

nohup commandは, nohup.out(or $HOME/nohup.out)にstdout,stderrを出力する.
出力できない場合は,nohup commandを実行できない.


・実は(?!), bash, tcsh, ksh なら, & を付けての実行だけでよい.
・zshは上記に該当しないので, nohupを使う.

2014年3月17日月曜日

サイクロマティック複雑度

「C.Jones Applied Software Measurement Second Edition 1991 McGraw-Hill
ソフトウェア開発の定量化法
共立出版」

1. 10 以下であればよい構造
2. 30 を越える場合,構造に疑問
3. 50 を越える場合,テストが不可能
4. 75 を越える場合,いかなる変更も誤修正を生む原因を作る

別な基準。(ちょっと厳しい)
 1-10  :良い。
 11-20 :少し複雑。危険度は小。
 21-50 :複雑。危険度は大。
 50以上:悪し。非常に危険!


sysrqd設定

sysrqd設定方法

sysrqdとは、マジックSysRqキーをnetwork超しにできるようにするdaemon

http://ja.wikipedia.org/wiki/%E3%83%9E%E3%82%B8%E3%83%83%E3%82%AFSysRq%E3%82%AD%E3%83%BC



【firewallを停止する(手っ取り早く設定するため)】

$ /sbin/chkconfig --list|grep iptabl
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off

# /sbin/chkconfig iptables off

# /sbin/chkconfig --list|grep iptabl
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off

# /etc/rc.d/init.d/iptables stop
ファイアウォールルールを適用中:                            [  OK  ]
チェインポリシーを ACCEPT に設定中filter                   [  OK  ]
iptables モジュールを取り外し中                            [  OK  ]



【sysrqd用のpassword fileを準備する】
# chmod a+x /etc/init.d/sysrqd_start
/etc/init.d/sysrqd_start
---------------------------------------------
#!/bin/sh
# chkconfig: 345 99 01
# description: sysrq
/home/user/bin/sysrqd &
exit 0
---------------------------------------------



【sysrqdの自動起動を設定する】

chkconfig --add sysrqd_start
# /sbin/chkconfig --list|grep sysrq
sysrqd_start    0:off   1:off   2:off   3:on    4:on    5:on    6:off
# /sbin/chkconfig --list|grep sysrqd
sysrqd          4094/tcp   # sysrq daemon
sysrqd          4094/udp   # sysrq daemon



【sysrqdを操作する】
$ telnet TARGET_HOST 4094 (teratermだとpasswrd入力で、Go away!になってしまう)
Trying x.y.z.a...
Connected to TARGET_HOST (x.y.z.a).
Escape character is '^]'.
sysrqd password: mypassword
sysrq> s (マウントされているすべてのファイルシステムをsyncする)
sysrq> u (マウントされているすべてのファイルシステムを読み込み専用モードで再マウントする。)
sysrq> b (即座に再起動する。この際ファイルシステムのsyncやアンマウントは行われない。)

refer to http://www.ubuntugeek.com/manage-linux-sysrq-over-network-using-sysrqd.html


【その他の方法】
・alt+SysRq+文字
 SysRq(PrintScreen)+ALT+s (disk sync
 SysRq(PrintScreen)+ALT+c (crash dumpfile出力、5分待ってみる)

 SysRq(PrintScreen)+ALT+b (reboot5分待ってみる)

# echo 1 >  /proc/sys/kernel/sysrq