2014年10月30日木曜日

Linux thread programming

http://www.tsoftware.jp/nptl/
参考にさせていただく.

2014年9月9日火曜日

tar 指定したfileのみarchive

tar 指定したfileのみarchive

$ find ./ -name '*.sh' -print0 | tar cv -T - --null -f fiels_sh.tar

find
-print0 null('\0')区切りでリストを作成

tar
-T アーカイブするファイル名のリストを指定したファイルから読み込み
ファイル名は,「-」.標準入力(標準出力)から読み込み(書き込み)
-null('\0')ファイル名のリストをnull区切りで読み取る

2014年8月26日火曜日

bash 文法まとめ

bash 文法まとめ

大変役に立つ.

http://motw.mods.jp/shellscript/tutorial.html#branch

2014年7月22日火曜日

emacs memo

option --debug-init 設定fileのdebug

MACROの保存:C-x (, C-x )
MACROの実行:C-x e
MACROの一時保存
M-x name-last-kbd-macro RET [name] RET

MACROの保存
init.el fileをopenして、
M-x insert-kbd-macro RET [name] RET
((fset '[name]…のS式が挿入される)

*scratch*での実行
C-j

Commentの挿入
M-;

man
M-x woman RET [command] RET
戻る:M-p
進む:M-n

一括置換(対話なし)
M-x replace-string

buffer全部を選択:C-x h
繰り返し実行:C-u 10

矩形モード
C-RET、範囲選択、入力や編集(C-w(cut))等の操作、C-g(終了)
C-RET、範囲選択、M-o(空白挿入)
C-RET、範囲選択、M-n(Numbering置換)
M-p矩形の幅を固定
M-b空白文字で埋める。 open-rectangle と同等
M-s文字列で置き換える。 string-rectangle と同等
M-f1種類の文字で埋める。 string-rectangle で1文字指定したときと同等
M-i矩形領域内の数字をインクリメントする
M-n矩形領域を連番で埋める。フォーマット指定可

cygwin
・windowの環境変数HOME(C:\cygwin64\home\user/)を新規追加
・.emacs.dをwindowsからcygwinへ移行(copy)

・ediff n:次の差分 p:前の差分 |:縦分割
・ElScreen
・undo-tree
・point-undo
・org-mode(アウトラインエディタ、Emacs 23以降)
・文字コード変換 C-x RET f


2014年7月18日金曜日

crash dump の準備

crash dumpの準備

 ・SysRq有効設定
  # echo 1 > /proc/sys/kernel/sysrq

  # /etc/sysctl.conf kernel.sysrq = 1
  # sysctl -p(設定有効化)
  # sysctl -a(確認)

 ・Disk空き容量確認 /var/crash


Sysq-key
– Alt-SysRq-c ← 'C'rach Dump
– Alt-SysRq-s ← 'S'ync
– Alt-SysRq-u ← '書き込み不可'で再mount
– Alt-SysRq-b ← re'B'oot

Sysrq-trigger
– # sync;sync;sync
– # echo 1 > /proc/sys/kernel/sysrq
– # echo c > /proc/sysrq-trigger

Linux crash dump に必要なもの

– debug版vmlinux(debug版kernel pkg)

• dump時のkernelと同一versionのdebug版のkernelのfileが必要
例) kernel-PAE-debuginfo-2.6.18-8.10AX.i686.rpm
kernel-debuginfo-2.6.18-8.10AX.x86_64.rpm

– System.map(通常のkernel pkgに含まれる)

• dump時のkernelが使用していたfile

– vmcore(dump本体:Memory Image) :/var/crash/日付/vmcore

2014年5月21日水曜日

printf pointer

#include

int main()
{
  int a=10;
  int *p = &a;

  printf("&a=0x%X p=0x%X p=%p *p=%d\n", &a, p, p, *p);
  return ;
}

2014年5月14日水曜日

bash pause read

bash pause command - under Linux / UNIX


read -p "Press [Enter] key to start backup..."

2014年4月22日火曜日

tcsh while loop

@ x = 1
while ($x <= 20)
     echo $x
@ x += 5
end

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

2014年1月31日金曜日

bash file loop

Directory内にある指定fileを検索し、コマンドを実行するひな形。

#!/bin/bash

#set -x

if [ $# -ne 1 ]; then
        echo "usage : ${0} [part_of_directory_string]"
        exit 1
fi

filter="Log_20140131"

#for target_file in $( ls . | grep ${filter} ); do
for target_file in ./${filter}*
do
        clear

        echo "------------------- ${target_file}"
        diff ${target_file}/* | less -S

#       read www
done

set +x

2014年1月14日火曜日