Linux重定向详解
转载:http://www.cnblogs.com/hexapodsoft/archive/2007/04/24/724902.html
I/O重定向详解及应用实例
1、 基本概念(这是理解后面的知识的前提,请务必理解)
a、 I/O重定向通常与 FD有关,shell的FD通常为10个,即 0~9;
b、 常用FD有3个,为0(stdin,标准输入)、1(stdout,标准输出)、2(stderr,标准错误输出),默认与keyboard、monitor、monitor有关;
c、 用 < 来改变读进的数据信道(stdin),使之从指定的档案读进;
d、 用 > 来改变送出的数据信道(stdout, stderr),使之输出到指定的档案;
e、 0 是 < 的默认值,因此 < 与 0<是一样的;同理,> 与 1> 是一样的;
f、 在IO重定向 中,stdout 与 stderr 的管道会先准备好,才会从 stdin 读进资料;
g、 管道“|”(pipe line):上一个命令的 stdout 接到下一个命令的 stdin;
h、 tee 命令是在不影响原本 I/O 的情况下,将 stdout 复制一份到档案去;
i、 bash(ksh)执行命令的过程:分析命令-变量求值-命令替代(``和$( ))-重定向-通配符展开-确定路径-执行命令;
j、
( ) 将 command group 置于 sub-shell 去执行,也称 nested
sub-shell,它有一点非常重要的特性是:继承父shell的Standard input, output, and error plus
any other open file descriptors。
k、 exec 命令:常用来替代当前 shell 并重新启动一个 shell,换句话说,并没有启动子 shell。使用这一命令时任何现有环境都将会被清除。exec 在对文件描述符进行操作的时候,也只有在这时,exec 不会覆盖你当前的 shell 环境。
2、 基本IO
cmd > file 把 stdout 重定向到 file 文件中;
cmd >> file 把 stdout 重定向到 file 文件中(追加);
cmd 1> fiel 把 stdout 重定向到 file 文件中;
cmd > file 2>&1 把 stdout 和 stderr 一起重定向到 file 文件中;
cmd 2> file 把 stderr 重定向到 file 文件中;
cmd 2>> file 把 stderr 重定向到 file 文件中(追加);
cmd >> file 2>&1 把 stderr 和 stderr 一起重定向到 file 文件中(追加);
cmd < file >file2 cmd 命令以 file 文件作为 stdin,以 file2 文件作为 stdout;
cat <>file 以读写的方式打开 file;
cmd < file cmd 命令以 file 文件作为 stdin;
cmd << delimiter Here document,从 stdin 中读入,直至
相关文档:
stroul,
strdup
snprintf()
atio
C中常用字符串操作函数
#include <string.h>
size_t strlen(const char *s) 测量字符串长度s的实际长度。
例如s[20]="abc",那么strlen(s)的结果是3,而不是20.这就是实际长度
char *strcat(const char *s1, const *s2) ......
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
在现实生活中被人们称为大师级的人物确实很少见。
Brian
Proffitt
先生就是一位全球知名、受人尊敬的
Linux
大师。此言有何根据?近日,他向我们推荐了什么?
......
//
同步问题:
对共享数据的访问,需要同步,互斥。
在中断,抢占,多CPU,多线程 环境下尤其重要。
同步分为: 阻塞同步,非阻塞同步
阻塞同步有许多实现方式了:mutex, semaphore. 阻塞同步使用不当就可能造成死锁,活锁,优先级反转。
非阻塞同步:(现在流行三种)
wait free 很难实现,思想是本线程有限步就 ......
/*
* 该文件主要实现的是truncate函数,该函数是释放指定i
* 节点在设备上占用的所有逻辑块,包括直接块、一次间
* 接块和二次间接块
*/
/*
* linux/fs/truncate.c
*
* (C) 1991 Linus Torvalds
*/
#include <linux/sched.h>
......
在/etc/rc.d/init.d/ 创建oracle10g文件
touch oracle10g
chmod a+x oracle10g
[root@test~]# vi /etc/rc.d/init.d/oracle10g
#!/bin/bash
#chkconfig:345 51 49
#description:starts the oracle database deamons
#
ORACLE_HOME=/oracle/product/10.2.0/db_1
ORACLE_OWNER=oracle
case "$1" in
start)
echo ......