Hunter的大杂烩 技术学习笔记

2014-09-15

异常处理之ThreadException、unhandledException及多线程异常处理[转]

Filed under: 技术话题 — hunter @ 12:52 pm

from:http://www.cnblogs.com/luminji/archive/2011/01/05/1926033.html

异常处理之ThreadException、unhandledException及多线程异常处理

 

一:ThreadException和unhandledException的区别

处理未捕获的异常是每个应用程序起码有的功能,C#在AppDomain提供了UnhandledException 事件来接收未捕获到的异常的通知。常见的应用如下: 

(more…)

2014-09-11

bash flock

Filed under: 技术话题 — hunter @ 9:34 pm
#!/bin/bash
{
flock -xn 3
if [ $? -ne 0 ];then
echo “Aready runing…”
exit 1
fi
do some thing here

} 3<>/tmp/`basename $0`.lock


bash执行命令各种情况分析

Filed under: 技术话题 — hunter @ 9:30 pm

from: http://blog.csdn.net/smstong/article/details/18352619

Linux系统中的可执行文件有多少种类?bash环境下是如何执行程序的?下面逐一分析。

1 Linux系统中可执行文件种类

1.1 二进制可执行文件

这种文件是最常见的,如/bin/ls,/sbin/ifconfig, /bin/cat等等。

[root@notebook135 ~]# file /bin/ls /bin/cat /sbin/ifconfig

/bin/ls:        ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

/bin/cat:       ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

/sbin/ifconfig: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

(more…)

bash 里的定时器

Filed under: 技术话题 — hunter @ 9:29 pm

from:http://blog.chinaunix.net/uid-600330-id-2088714.html


#function : begin_timer HANDLER_NAME MICROSECONDS CMD_ON_TIMEOUT ARGS...
# @HANDLER_NAME : handler of timer
# @MICROSECONDS : micro seconds to wait
# @CMD_ON_TIMEOUT ARGS : command and its arguments to run when timeout
start_timer(){
[ $# -lt 2 ] && return 1
HANDLER=$1
TIMER=$2
shift 2
(
trap exit USR1
sleep $TIMER
"$@"
)&
eval export $HANDLER=$!
}
export -f start_timer
(more...)

Bash编程陷阱一

Filed under: 技术话题 — hunter @ 9:28 pm

from:http://www.oenhan.com/bash-pitfalls-1

Bash编程陷阱:bash-pitfalls里面介绍了43条shell陷阱,都是一些很常见的应用场景,新手和老手都有可能犯的错误,为了加深记忆,自己就大致记录下来,英文文章用wiki编辑,条目随时可能增加,建议直接看英文。

如下的内容不完全翻译原文,穿插了一些自己的修改。

1. for i in $(ls *.mp3)

bash编程中最常见的错误之一就是把循环写出如下样子:

1
2
3
4
5
6
7
8
9
for i in $(ls *.mp3); do    # Wrong!
   some command $i          # Wrong!
done
for i in $(ls)              # Wrong!
for i in `ls`               # Wrong!
for i in $(find . -type f)  # Wrong!
for i in `find . -type f`   # Wrong!

(more…)

Older Posts »

Powered by WordPress