关于read(...)返回值的正确判断:p30
File I/O 的 read(...)函数用法:
有问题的代码,只判断返回值为-1的情况。
unsigned long word;
ssize_t nr;
/* read a couple bytes into 'word' from 'fd' */
nr = read (fd, &word, sizeof (unsigned long));
if (nr == -1)
/* error */
Indeed, a call to read( ) can result in many possibilities:
• The call returns a value equal to len. All len read bytes are stored in buf. The
results are as intended.
• The call returns a value less than len, but greater than zero. The read bytes are
stored in buf. This can occur because a signal interrupted the read midway, an
error occurred in the middle of the read, more than zero, but less than len bytes’
worth of data was available, or EOF was reached before len bytes were read.
Reissuing the read (with correspondingly updated buf and len values) will read the
remaining bytes into the rest of the buffer, or indicate the cause of the problem.
• The call returns 0. This indicates EOF. ......
原始定义:include/linux/init.h
__init和__exit标记函数,__initdata和__exitdata标记数据。
此宏定义可知标记后的函数与数据其实是放到了特定的(代码或数据)段中。标记为初始化的函数,表明该函数供在初始化期间使用。在模块装载之后,模块装载就会将初始化函数扔掉。这样可以将该函数占用的内存释放出来。
__exit修饰词标记函数只在模块卸载时使用。如果模块被直接编进内核则该函数就不会被调用。如果内核编译时没有包含该模块,则此标记的函数将被简单地丢弃。
_init不属于c的标准在内核代码里,这个表示把这个函数放在.init.text section里,在include/linux/init.h里有定义
#define __init __attribute__ ((__section__ (".init.text")))
这个section的空间是会被回收的,section是和连接有关的概念 ......
http://linux.vbird.org/linux_server/0140networkcommand.php
使用路由方式,使用route命令。
-- Route命令的正确用法
使用 Route 命令行工具查看并编辑计算机的 IP 路由表。Route 命令和语法如下所示:
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
-f 清除所有网关入口的路由表。
-p 与 add 命令一起使用时使路由具有永久性。
Command 指定您想运行的命令 (Add/Change/Delete/Print)。
Destination 指定该路由的网络目标。
mask Netmask 指定与网络目标相关的网络掩码(也被称作子网掩码)。
Gateway 指定网络目标定义的地址集和子网掩码可以到达的前进或下一跃点 IP 地址。
metric Metric 为路由指定一个整数成本值标(从 1 至 9999),当在路由表(与转发的数据包目标地址最匹配)的多个路由中进行选择时可以使用。
if Interface 为可以访问目标的接口指定接口索引。若要获得一个接口列表和它们相应的接口索引,使用 route print 命令的显示功能。可以使用十进制或十六进制值进行接口索引。
/? 在命令提示符处显示帮助。
示例
若要显示 IP 路由表的全部内容,请键入:
route print ......
原创文章,转载请注明出处,谢谢!
作者:清林,博客名:飞空静渡
在linux的进程中可以接收到各种的信号,并且如果你不对信号进行处理,linux中的进程就会采用默认的处理方式处理,比如ctrl-c的信号,进程对它的处理就是终止进程的执行。
在linux中,我们也可以在进程中屏蔽掉某些信号,使进程不去处理这些信号,但其中的SIGKILL和SIGSTOP是不能被阻塞的。
在这里先介绍几个信号的函数:
int sigempty(sigset_t *set); // 清空信号集set
int sigfillset(sigset_t *set); // 填满信号集,即让set包含所有的信号
int sigaddset(sigset_t *set, int signo); // 在set中增加signo信号
int sigdelset(sigset_t *set, int signo); // 在set中去掉signo信号
int sigismember(sigset_ ......
服务器:
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <time.h>
#define SERVER_PORT 20000 // define the defualt connect port id
#define LENGTH_OF_LISTEN_QUEUE 10 //length of listen queue in server
#define BUFFER_SIZE 255
#define WELCOME_MESSAGE "welcome to connect the server. "
int main(int argc, char **argv)
{
int servfd,clifd;
struct sockaddr_in servaddr,cliaddr;
if ((servfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
{
printf("create socket error!\n");
exit(1);
}
&n ......
1. java ... > log.out
将Java程序输出 保存到 log.out 文件
2. java .... >>log.out
与上一个不同,这个是追加到文件,而不会覆盖原有输出.
3. java .... >>log.out 2>&1
在Java里(其他语言也应该一样), 程序的输出分为 标准输出流和错误输出流, 2>1& 是指将程序的错误信息输出也输出到控制台,
4. $! 获得进程号
java .... &
echo $!
就可以获得这个java的进程号了
5. $? 获得返回值
java.... &
echo $?
可以获得程序的返回值 ......