分页: 19/105 第一页 上页 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 下页 最后页 [ 显示模式: 摘要 | 列表 ]
#include <iostream>                                                                  
using namespace std;                                                                      
struct ENTINFO {                                                                          
  char ent_add[255];                                                                      
};                                                                                        
typedef struct ENTINFO _ENTINFO;                                        
int main(int argc, char *argv[])                                                          
{                                                                                                                                                
  _ENTINFO *ent_info_pointer;                                                              
  _ENTINFO ent_info[1024];                                                                
  memset(ent_info,0,sizeof(_ENTINFO)*1024);                                                
  strcpy(ent_info[0].ent_add,"guangdong shenzhen nanshan new haofang garden");            
  strcpy(ent_info[1].ent_add,"guangdong shenzhen nanshan haofang garden");                
  strcpy(ent_info[2].ent_add,"guangdong shenzhen nanshan haofang garden 6 floor");          
  ent_info_pointer = ent_info;                                                            
  printf("ent_info_pointer->ent_add=%s\n",ent_info[0].ent_add);                            
  printf("ent_info_pointer->ent_add=%s\n",ent_info[1].ent_add);                            
  printf("ent_info_pointer->ent_add=%s\n",ent_info[2].ent_add);                            
  printf("ent_info_pointer->ent_add=%s\n",ent_info_pointer->ent_add);                      
  ent_info_pointer++;                                                                      
  printf("ent_info_pointer->ent_add=%s\n",ent_info_pointer->ent_add);                      
  ent_info_pointer++;                                                                      
  printf("ent_info_pointer->ent_add=%s\n",ent_info_pointer->ent_add);                      
  return 0;                                                                                
}
                                                                                        
                                                                                          

运行结果:
ent_info_pointer->ent_add=guangdong shenzhen nanshan new haofang garden
ent_info_pointer->ent_add=guangdong shenzhen nanshan haofang garden
ent_info_pointer->ent_add=guangdong shenzhen nanshan haofang garden 6 floor
ent_info_pointer->ent_add=guangdong shenzhen nanshan new haofang garden
ent_info_pointer->ent_add=guangdong shenzhen nanshan haofang garden
ent_info_pointer->ent_add=guangdong shenzhen nanshan haofang garden 6 floor

strcture_array_test.cpp



root@17*.2*.38.78:~/c++/struct# ./a.out
No.  Name  sex  age   Score
10101Tom                  M  18   0
10102John                 M  19   0
10103Mary                 F  17   0
Grep -E参数,加上正则表达式实现,多个函数查找,如下:
grep -Erin 'atoi|itoa|atol|ltoa|intval'  ./

配上shell 文件 findfunPath.sh如下:
#!/bin/bash
findPath=$1
#judge folder is exist
if [ ! -d "$findPath" ]; then
    echo "Sorry,Input path is not exist.";
    echo "You can try follow command to check it: ls ${findPath}";
    exit 0
fi
grep -Erin 'atoi|itoa|atol|ltoa|intval'  ${findPath}|awk -F":" '{print "\nFileLineNumber=" $2 "     ExistFileName=" $1 "\nDetailInfo
=" $0}'

简单示例:
findfunPath.sh /usr/local/pro/

找出消耗内存最多的前10名进程
# ps -auxf | sort -nr -k 4 | head -10
找出使用CPU最多的前10名进程
# ps -auxf | sort -nr -k 3 | head -10

特别是默认空格,的时候,可以通过:
cat outok.txt |awk '{print $5}'|sort -k 1

来得知是第几列:awk输出$1,$2,$3挨个看看就知道了。
示例:
sort  -k5 outok.txt
//第5咧排序即可,空格分割。

参数说明:
sort的-r选项:
sort默认的排序方式是升序,如果想改成降序,就加个-r就搞定了。
sort的-u选项:
它的作用很简单,就是在输出行中去除重复行。
sort的-n选项:
我们如果想改变这种现状,就要使用-n选项,来告诉sort,“要以数值来排序”!
sort提供了-t选项,后面可以设定间隔符。
指定了间隔符之后,就可以用-k来指定列数了。


参数:
-t表示分割符,以:分割,默认情况下以空格分割
-k作用是根据某个列来排序,这里根据第3列,默认是第1列(从1开始)。
-n按照数字方式排序。不加-n参数时排序结果根据最左面的数字开始,等同于字母的比较方式。
=========================================================


其他的sort常用选项

-f会将小写字母都转换为大写字母来进行比较,亦即忽略大小写

-c会检查文件是否已排好序,如果乱序,则输出第一个乱序的行的相关信息,最后返回1

-C会检查文件是否已排好序,如果乱序,不输出内容,仅返回1

-M会以月份来排序,比如JAN小于FEB等等

-b会忽略每一行前面的所有空白部分,从第一个可见字符开始比较。

=========================================================
阅读全文
使用Memcached实现Session共享阅读全文
if elif else demo:
#example
if [ $1 -gt 90 ];then
    echo "Good, $1"
elif [ $1 -gt 70 ];then
    echo "OK, $1"
else
    echo "Bad, $1"
fi


wile demo:
#example
i=1
sum=0
while test $i -le 100
do
    let sum=$sum+$i
    let i=$i+1
done
echo "1+2+3...+100="$sum

函数示例:
#example
function add()
{
        let $3=$1+$2
}
add 1 2 ret
echo $ret
  grep -v ^$ oldfile >newfile

  但是似乎在FreeBSD下面不行,会不会是grep版本的问题?

  后来想到了很刁的vim的全局替换,最后成功

  vim的命令为:%s/^\n//g

  意思是全局替换所有以回车开头的字符,替换为空。

  顺便研究了一下

  如果有多个连续的空行,想保留一个

  vim的命令为:%s/^\n$//g

原文出自:http://soft.chinabyte.com/os/120/11507620.shtml
g r e p命令加- E参数,这一扩展允许使用扩展模式匹配。例如,要抽取城市代码为2 1 9或2 1 6,方法如下:
[sam@chenwy sam]$ grep -E '219|216' data.f
219     dec     2CC1999 CAD     23.00 PLV2C 68
216     sept 3ZL1998 USP     86.00 KVM9E 234


我采用:
grep -Erin 'atoi|itoa|atol|ltoa'  ./

~/grep# grep -Erin 'atoi|itoa|atol|ltoa'  ./
./itoa.txt:1:itoa
./itoa.txt:2:atoi
./itoa.txt:3:atoi
./itoa.txt:4:atoi
./itoa.txt:5:atoi
./atoi.txt:1:atoi
./atoi.txt:2:atoi
./atoi.txt:3:atoi
./atoi.txt:4:atoi
./atoi.txt:5:atoi
./atol.txt:1:atol
./atol.txt:2:atol
./atol.txt:3:atol
./atol.txt:4:atol
./atol.txt:5:atol
./atol.txt:6:atol
./ltoa.txt:1:ltoa
./ltoa.txt:2:ltoa
./ltoa.txt:3:ltoa
./ltoa.txt:4:ltoa
./ltoa.txt:5:ltoa
./ltoa.txt:6:ltoa

阅读全文
亦庄,立足于北京国际新城的新高度,随着政策的利好导向,正在高速前行,成为北京在世界的代言。亦庄路东区作为以产业为主导功能的片区成为重点区域。丰富的交通资源为区域发展提供动力,亦庄线、M12线在此交会, 2010年年底开通的轻轨亦庄线,北接地铁5号线,20分钟直抵宋家庄。M12建成后通达国贸,将与CBD区域融合。

双轨建构 京南置业黄金点
距L2和M12换乘站经海路站仅280米VITA国际,于2010年11月11日破土动工, 11月12日售楼处开放。是目前北京距离地铁最近的在售低总价精装小户型,业主出门即可便捷接入北京城市地铁网。在经历通州、奥北、中关村等轻轨沿线不动产购置热潮之后,VITA国际的轨道效应将引领新一轮资本流向,开启全新地铁时代。
与VITA国际一个街区之隔,将建造亦庄的公交枢纽站,届时公交枢纽将实现“零距离”换乘。VITA国际门前双轨交会,瞬间直抵繁华。
保守估计:从开盘到交房每平米净赚4000非常轻松。仅供参考!
欢迎来电垂询:13269811169 陈娅婷
11月20日正式接受排号!排号可享受优惠!
首先博主抛出一个疑问,如何实现windows和linux之间的rpc通信,这两个异构的系统如何才能建立变量传递通道,这相当困扰博主,如有好心人指点,将不胜感激。
好了,现在切入正题:今天博主在linux环境下实现了一个小小RPC通信,按照惯例,做一下总结吧。
原先博主用的是Red hat9,安装完red hat后不想系统不带GCC,然后博主跑遍各大linux论坛搜寻装GCC的步骤,虽然取得些微的进步,对linux也有一些初步的认识了,但是系统还是不能用。无奈,博主就跑去问老师如何解决linux安装C编译器,不想linux老师来了一句这个red hat他已经不玩好多年了,然后建议我去玩ubuntu。于是,博主就屁颠屁颠地跑去下载最新的ubuntu 10.4,然后安装。出乎意料的是,ubuntu安装要比red hat方便多了,基本属于傻瓜式操作。
所以,接下来博主要讲的基本都是基于ubuntu 10.4平台的。
虽然是新平台,但是ubuntu用的还是linux内核,所以基本和red hat差不多,只有些微差别。
这次操作比上次在red hat上操作顺利多了,博主是参照下文的步骤一步一步实现rpc的:
1.        根据rpc调用的功能,先不考虑rpc调用,编写一个平常的实现相应功能的程序。
如一个远程的文件传输的rpc调用,平常程序便是考虑文件存储在本地,直接打开读便可,如下:
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 20
#define MAXLENGTH 1024
char * readfile(char *);
int main()
{
    char name[MAXNAME];
    printf("Enter File Name: ");
    scanf("%s", name);
    printf("%s", readfile(name));
}
char * readfile(char * name)
{
    FILE *file = fopen(name, "r");
    char * buf = (char *)malloc(sizeof(char)*MAXLENGTH);
    if (file == NULL)
    {
        printf("File Cann't Be Open!");
        return 0;
    }
    printf("The File Content is : \n");
    while (fgets(buf, MAXLENGTH-1, file) != NULL)
    {
        return buf;
    }
    return NULL;
}
2.        把程序拆分为两部分,main函数和readfile函数,带有main的一部分是主动发起调用的,在rpc中相当于客户端,带有readfile函数的部分是提供相应的功能的,相当于服务器端。将代码拆分后要在客户端添加相应的rpc调用函数,clnt_create(RMACHINE, FILETRANSPROG, FILETRANSVERS,"tcp");
FILETRANSPROG便是trans.x中的程序名,FILETRANSVERS是版本名,使用tcp进行rpc调用。
拆分后代码如下:
客户端client.c:
#include <rpc/rpc.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#include "trans.h"
#define WSVERS MAKEWORD(0, 2)
#define RMACHINE "localhost"
CLIENT *handle;
#define MAXNAME 20
#define MAXLENGTH 1024
char * readfile(char *);
int main()
{
    char name[MAXNAME];
    char * buf;
    printf("Enter File Name: ");
    scanf("%s", name);
   handle = clnt_create(RMACHINE, FILETRANSPROG, FILETRANSVERS,"tcp");
   if (handle == 0) {
         printf("Could Not Connect To Remote Server.\n");
         exit(1);
   }
    buf = readfile(name);
    printf("%s", buf);
    return 0;
}
服务器端server.c:
#include <rpc/rpc.h>
#include <stdio.h>
#include <stdlib.h>
#include "trans.h"
#define MAXNAME 20
#define MAXLENGTH 1024
char * readfile(char * name)
{
    FILE *file = fopen(name, "r");
    char * buf = (char *)malloc(sizeof(char)*MAXLENGTH);
    if (file == NULL)
    {
        printf("File Cann't Be Open!");
        return 0;
    }
    printf("The File Content is : \n");
    while (fgets(buf, MAXLENGTH-1, file) != NULL)
    {
        return buf;
    }
    return NULL;
}
3.        编写***.x文件。具体步骤可以参考Douglas的那本Internetworking With TCP/IP 的第三卷,客户端-服务器端编程与应用。
本程序的.x文件命名为trans.x内容如下:
const MAXLENGTH = 1024;
const MAXNAME = 20;
program FILETRANSPROG  //程序名
{
    version FILETRANSVERS  //版本名
    {
        string READFILE(string) = 1;  //调用的方法名
    } = 1;
} = 99;
4.        使用rpcgen编辑.x文件,在linux下输入命令
rpcgen   trans.x
若格式正确,编译无错误则产生三个文件trans.h,trans_svc.c(服务器端),trans_clnt.c(客户端)。因为上述trans.x中无自定义数据结构,所以没有xdr文件产生。
trans.h代码:
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _TRANS_H_RPCGEN
#define _TRANS_H_RPCGEN
#include <rpc/rpc.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAXLENGTH 1024
#define MAXNAME 20
#define FILETRANSPROG 99
#define FILETRANSVERS 1
#if defined(__STDC__) || defined(__cplusplus)
#define READFILE 1
extern  char ** readfile_1(char **, CLIENT *);
extern  char ** readfile_1_svc(char **, struct svc_req *);
extern int filetransprog_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t);
#else /* K&R C */
#define READFILE 1
extern  char ** readfile_1();
extern  char ** readfile_1_svc();
extern int filetransprog_1_freeresult ();
#endif /* K&R C */
#ifdef __cplusplus
}
#endif
#endif /* !_TRANS_H_RPCGEN */
trans_svc.c代码:
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "trans.h"
#include <stdio.h>
#include <stdlib.h>
#include <rpc/pmap_clnt.h>
#include <string.h>
#include <memory.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif
static void
filetransprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
{
   union {
            char *readfile_1_arg;
   } argument;
   char *result;
   xdrproc_t _xdr_argument, _xdr_result;
   char *(*local)(char *, struct svc_req *);
   switch (rqstp->rq_proc) {
   case NULLPROC:
            (void) svc_sendreply (transp, (xdrproc_t) xdr_void, (char *)NULL);
            return;
   case READFILE:
            _xdr_argument = (xdrproc_t) xdr_wrapstring;
            _xdr_result = (xdrproc_t) xdr_wrapstring;
            local = (char *(*)(char *, struct svc_req *)) readfile_1;
            break;
   default:
            svcerr_noproc (transp);
            return;
   }
   memset ((char *)&argument, 0, sizeof (argument));
   if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
            svcerr_decode (transp);
            return;
   }
   result = (*local)((char *)&argument, rqstp);
   if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
            svcerr_systemerr (transp);
   }
   if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
            fprintf (stderr, "%s", "unable to free arguments");
            exit (1);
   }
   return;
}
int
main (int argc, char **argv)
{
   register SVCXPRT *transp;
   pmap_unset (FILETRANSPROG, FILETRANSVERS);
   transp = svcudp_create(RPC_ANYSOCK);
   if (transp == NULL) {
            fprintf (stderr, "%s", "cannot create udp service.");
            exit(1);
   }
   if (!svc_register(transp, FILETRANSPROG, FILETRANSVERS, filetransprog_1, IPPROTO_UDP)) {
            fprintf (stderr, "%s", "unable to register (FILETRANSPROG, FILETRANSVERS, udp).");
            exit(1);
   }
   transp = svctcp_create(RPC_ANYSOCK, 0, 0);
   if (transp == NULL) {
            fprintf (stderr, "%s", "cannot create tcp service.");
            exit(1);
   }
   if (!svc_register(transp, FILETRANSPROG, FILETRANSVERS, filetransprog_1, IPPROTO_TCP)) {
            fprintf (stderr, "%s", "unable to register (FILETRANSPROG, FILETRANSVERS, tcp).");
            exit(1);
   }
   svc_run ();
   fprintf (stderr, "%s", "svc_run returned");
   exit (1);
   /* NOTREACHED */
}
trans_clnt.c代码:
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include <memory.h> /* for memset */
#include "trans.h"
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };
char **
readfile_1(char **argp, CLIENT *clnt)
{
   static char *clnt_res;
   memset((char *)&clnt_res, 0, sizeof(clnt_res));
   if (clnt_call (clnt, READFILE,
            (xdrproc_t) xdr_wrapstring, (caddr_t) argp,
            (xdrproc_t) xdr_wrapstring, (caddr_t) &clnt_res,
            TIMEOUT) != RPC_SUCCESS) {
            return (NULL);
   }
   return (&clnt_res);
}
5.        编写客户端和服务器端接口。此部分可以说是最麻烦的部分,稍不注意便会出错,同样可以参考Douglas的那本书,但要注意的是他的服务器接口例程代码中的每个函数的第二个参数应该是CLIENT *clnt, 而非struct svc_req * rqstp
为本程序编写的代码如下:
客户端接口文件trans_cif.c:
#include <rpc/rpc.h>
#include <stdio.h>
#include "trans.h"/* Client-side stub interface routines written by programmer */
extern CLIENT * handle;
static char **ret;
char * readfile(char * name)
{
   char ** arg;
   arg = &name;
   ret = readfile_1(arg, handle);
   return ret==NULL ? NULL : *ret;
}
服务器端接口文件trans_sif.c:
#include <rpc/rpc.h>
#include <stdio.h>
#include "trans.h"
char * readfile(char *);
static char * retcode;
char ** readfile_1(char ** w, CLIENT *clnt)
{
   retcode = readfile(*(char**)w);
   return &retcode;
}
6.        编译链接客户端和服务器端程序
不管是客户端还是服务器端,都要链接三个文件,
客户端:程序文件+*** _clnt.c+客户端接口文件。
服务器端:程序文件+*** _svc.c+服务器端接口文件
同时每一段的三个文件都是互相关联的,编译出现错误时,可以根据提示查看三个文件进行debug
命令如下:
gcc -Wall -o trans_client client.c trans_clnt.c trans_cif.c
gcc -Wall -o trans_server server.c trans_svc.c trans_sif.c
7.        启动服务器端和客户端,大功告成。要先运行服务器端程序,再运行客户端程序。命令如下:
./trans_server
./trans_client
client启动后,提示输入要传输的文件名,输入后,server将文件的第一行传回,大功告成!
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/symbol89/archive/2009/06/21/4285142.aspx
----------------------------------------------------------------------------------------------------------------------------------------------------
博主按照上面的指示一步一步做下来,还算顺利。但是在链接服务端文件时爆出一个错误,意思是trans_svc.c这个文件有个undefined reference to 'readfile_1_svc'错误,经本人亲测,是由于trans_svc.c文件第37行原本应该是local = (char*(*)(char *,struct svc_reg *))readfile_1;的,但是rpc编译器翻译成local = (char*(*)(char *,struct svc_reg *))readfile_1_svc ,所以把_svc去掉就好了。
这里不得不提的是ubuntu的vi编辑器相当不好用。即没有装vim,操作起来也没有red hat的vi编译器那样用的那么顺手。这里强烈推荐鸟哥的vi编辑器入门手册。把vi编译器介绍的很详细,附上地址:http://linux.vbird.org/linux_basic/0310vi.php。
vi编辑器模式图(转载自鸟哥的私房菜)
vi模式下指令汇总(转载自鸟哥的私房菜)
最后强烈推荐《鸟哥的私房菜》这本书,相当棒的讲解linux的一套书(有专门的网站)。分上下册,上册讲解linux的基本知识和指令,下册讲linux架站的知识。很实用。
-----------------------------------------------------------------------------------------------------------------------------------------------------
最后运行./trans_server时系统会爆出cannot connect to...的错误(具体的我也忘了),这是由于linux默认把端口映射服务关闭的缘故。这时可以参照下面的解决方法:
$ sudo apt-get install nfs-kernel-server nfs-common portmap
$ sudo dpkg-reconfigure portmap
在出现如下提示的时候,注意选定“不将portmap 绑定在loopback 地址”
之后,系统会有如下提示:
Current registered services:
------------------------------------------------
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs

100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
之后通过查看 /etc/default/portmap, 确保
#OPTIONS="-i 127.0.0.1"
前面的#号 被添加了
重启portmap服务:
$ sudo /etc/init.d/portmap restart
这样就可以了,但是要用root权限执行。
到这里所有我所遇到的问题都解决了,但是博主仍有疑问,如何实现windows和linux之间的rpc通信,这两个异构的系统如何才能建立变量传递通道,这相当困扰博主,如有好心人指点,将不胜感激。
本文出自 “只争朝夕” 博客,请务必保留此出处http://xiaovfight.blog.51cto.com/1625426/398745
fms在centos linux 4.x上可以正常安装,装完了就可以自已自动启来了。但是在centos linux 5.x上,装完后启动不了。日志内也没有任何错误信息。

安装:

./installFMS -platformWarnOnly

安装完成后FMS服务没有自动启来,日志内也没有任何错误信息。

我们通过看/etc/init.d/fms这个启动脚本,发现FMS启动主要是用到了fmsmaster start。手动跑fmsmaster start发现出错。

[root@fms1 fms]# ./fmsmaster start
./fmsmaster: error while loading shared libraries: libssl.so.4: cannot open shared object file: No such file or directory

libssl.so.4是这个链接,在5.x上版本上没有建,手动建立:

[root@fms1 fms]# ln -s /usr/lib/libssl.so /usr/lib/libssl.so.4

再启动:
[root@fms1 fms]# ./fmsmaster start                              
./fmsmaster: error while loading shared libraries: libcrypto.so.4: cannot open shared object file: No such file or directory

再建链接:
[root@fms1 fms]# ln -s /usr/lib/libcrypto.so /usr/lib/libcrypto.so.4

OK,FMS可以正常启动了。

来源:http://hi.baidu.com/farmerluo/blog/item/32bfd42a7790d398023bf65e.html
参考:http://mimieye.iteye.com/blog/103755
         http://blog.bj50.net/black/?p=184

下载:http://blog.csdn.net/xiang08/article/details/4136670
https://www.adobe.com/cfusion/tdrc/index.cfm?loc=zh_cn&product=flashmediaserver
每个周日10点,重启Apache Server:
10 1 * * 0   /usr/local/apache2/bin/apachectl restart

*  *  *  *  *  program
分  时  日  月  周        命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
当第1列 为 * 时表示每分钟都要执行 program,第2列为 * 时表示每小时都要执行程式,其余类推
当第1列为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,第2列为 a-b 时表示从第 a 到第 b 小时都要执行,其余类推
当第1列为 */n 时表示每 n 分钟个时间间隔执行一次,第2列 为 */n 表示每 n 小时个时间间隔执行一次,其余类推
当第1列为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,第2列 为 a, b, c,... 时表示第 a, b, c...个小时要执行,其余类推

crontab文件的一些例子:
30 21 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每晚的21:30重启lighttpd 。
45 4 1,10,22 * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每月1、10、22日的4 : 45重启lighttpd 。
10 1 * * 6,0 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每周六、周日的1 : 10重启lighttpd 。
0,30 18-23 * * * /usr/local/etc/rc.d/lighttpd restart
上面的例子表示在每天18 : 00至23 : 00之间每隔30分钟重启lighttpd 。
0 23 * * 6 /usr/local/etc/rc.d/lighttpd restart
上面的例子表示每星期六的11 : 00 pm重启lighttpd 。
* */1 * * * /usr/local/etc/rc.d/lighttpd restart
每一小时重启lighttpd
* 23-7/1 * * * /usr/local/etc/rc.d/lighttpd restart
晚上11点到早上7点之间,每隔一小时重启lighttpd
0 11 4 * mon-wed /usr/local/etc/rc.d/lighttpd restart
每月的4号与每周一到周三的11点重启lighttpd
0 4 1 jan * /usr/local/etc/rc.d/lighttpd restart
一月一号的4点重启lighttpd
为了省却不必要的麻烦,请尽量在编译安装时直接加上 --enable-deflate --enable-headers 参数
阅读全文
最近发现一个问题:
window.location.href在IE6下面竟然不跳转,这是为什么呢?
这个是我写的语句:
<a href="javascript:void(0);" ;onclick="javascript:window.location.href='http://www.sina.com';">转到新浪</a>
后面是网上找到了解决方案(URL:http://www.cnblogs.com/kaima/archive/2008/08/22/1273808.html):
<script type="text/javascript">
function goUrl(x)
{
     window.location.href=x;
}
</script>
<a href="javascript:;" onclick="javascript:goUrl('http://www.sina.com');">跳转1</a>
<a href="javascript:void(0);" onclick="javascript:goUrl('http://www.sina.com');">跳转2</a>
<a href="javascript:void(0);" onclick="javascript:goUrl('http://www.sina.com');return false;">跳转3</a>
<a href="#" onclick="javascript:goUrl('http://www.sina.com');">跳转4</a>
<a href="###" onclick="javascript:goUrl('http://www.sina.com');">跳转5</a>
测试环境IE6,IE7,Firefox 3。
跳转1和2在IE6环境下无效,3、4、5在IE6,IE7,Firefox3.01下测试均能 通过,。
跳转4和5最简洁。
关键在于<a>的href属性,空链接用"#","###"。
为了不返回网页顶端。
空链接推荐用"###"。

我采用了第三种方法,在后面加了return false;这样,IE6、IE7、FF3下面全部通过。

来源:http://blog.163.com/leaf-shi/blog/static/12749133020098109215329/
target:
        ls -b $(BINDIR)/*.o $(BINDIR)/*.a $(BINDIR)/ent_rpcserver > target


阅读全文
vi as v command:

vi ~/.bash_profile
source ~/.bash_profile
alias v=vi;

阅读全文
Smarty最大的功能是做模版的页面缓存。也就是通过Smarty可以完成两个步骤:编译+解析
第一步:编译。是指把模版文件的标签替换为纯php,再保存在缓存位置,保存的文件扩展名是PHP,我把这个步骤叫做编译(这是我自己的叫法,不是官方的)
第二步:解析。也就是把刚才编译的PHP文件解析执行而已~~这个就不用多做解释了
切入正题,在Smarty.class.php文件中加入如下代码
function MakeHtmlFile($file_name, $content)
     {     //目录不存在就创建
         if (!file_exists (dirname($file_name))) {
              if (!@mkdir (dirname($file_name), 0777)) {
                      die($file_name."目录创建失败!");
              }
          }
          if(!$fp = fopen($file_name, "w")){
              echo "文件打开失败!";
              return false;
          }
          if(!fwrite($fp, $content)){
              echo "文件写入失败!";
             fclose($fp);
              return false;
          }
         fclose($fp);
         chmod($file_name,0666);
      }

这个函数的作用就是保存文件~~
调用方法如下
require '../libs/Smarty.class.php';
$smarty = new Smarty;
//&hellip;&hellip;&hellip;&hellip;省略变量定义和赋值
//$smarty->display('index.tpl');
$content=$smarty->fetch("index.tpl");
$smarty->MakeHtmlFile('./index.html',$content);//生成

来源:http://blog.163.com/junsheng_zheng/blog/static/110710882200911211162510/
大家都知道Linux下有一个man(manual),相当man的,并且经常找他帮忙解决问题
$ man ...
No manual entry for ...
但是发现有时候他不理睬你,说明有些manpage没有安装,得自己安装上,这样用起来就方便些
在ubuntu 7.04下
$ sudo apt-get install binutils-doc cpp-doc gcc-4.1-doc gcc-doc glibc-doc libstdc++6-4.1-doc stl-manual cpp-4.1-doc manpages manpages-dev
如果是其他版本,可以先搜索一下,再安装,例如
$ sudo apt-cache search libstdc++6
至于其他的发行版,使用相应的软件管理工具把对应的包安装上即可。
比如slackware下可以用slapt-get,gentoo下用emerge,使用起来都很方便。
关于如何获取man的欢心以便取得更大的无偿帮助,大家需要熟悉他的秉性才成
如果记不清楚工具或者函数的完整名字,可以考虑用-k参数,例如,查找和printf有关的帮助:
$ man -k printf
如果还有一些其他的约束信息,可以用grep过滤一下
$ man -k printf | grep ^printf
如果仅仅想了解什么是什么,可以用-f参数
$ man -f printf

$ whatis printf
另外,man会有很多不同的面孔(区段),你在man后面加上不同的数字就可以一睹他的所有真容啦,这些数字对应如下:
区段1:用户指令
区段2:系统调用
区段3:程序库调用
区段4:设备
区段5:文件格式
区段6:游戏
区段7:杂项
区段8:系统指令
区段9:内核内部指令
区段n:Tcl或Tk指令
例如,查看printf命令的帮助:
$ man printf
而要查看函数库中的printf函数的帮助:
$ man 3 printf
而有些区段可能根本就没有,比如,你不要打算找出printf的系统调用帮助,因为没有这样系统调用
$ man 2 printf
No entry for printf in section 2 of the manual
$ cat /boot/System.map | grep " sys_printf$"
$ cat /boot/System.map | grep " sys_exit$"
$ man 2 exit
上面说明,如果有对应的面孔(区段)才有可能看到,当然你还得安装这些文档才成,而且这些文档要确实存在才成
如果还想深入了解man,你就man一下man吧,看看一下他的“内心”
$ man man
学会如何查找帮助也是一门技术,man很man,但是需要你主动去“追”他才成  加油!
参考资料:
中文版的manpage of man:
http://cmpp.linuxforum.net/cman-html/man1/man.1.html
补充:
在vim编辑器里头,可以通过大写字母K获取光标位置处相关内容的帮助,比如你把光标定位到printf,然后,按下ESC,再按下SHIFT+k就可以获取帮助啦。
来源:http://oss.lzu.edu.cn/modules/newbb/viewtopic.php?topic_id=1179&forum=6
前员工曝雅虎失败原因:不注重产品研发:
产品研发,不等于研发,一切技术都以如何注入到产品中,进而提高产品的竞争力的实践和思索,才是产品研发。---Jackxiang

阅读全文
关于“RPC语言”
RPC语言也是一种专门的编程语言,当然这里我们不需要知道太多,只需要能看懂下面这种基本结构就行了:
program TESTPROG {
   version VERSION {
     string TEST(string) = 1;
   } = 1;
} = 87654321;
这里TESTPROG和VERSION是两个变量,用于标识一个单独的RPC接口。这被RPC服务程序,比如portmap用到,我们可以不用关心,变量名字也是随便取的。但取值要在你的系统中是唯一的。
“string TEST(string) = 1;”这一行说明有两个函数test_VERSION和test_VERSION_svc,这里由于VERSION变量为1,所以函数名为test_1和 test_1_svc,这两个函数用于在服务器端和客户端实现调用,即:
在客户端调用test_1函数,服务器端调用test_1_svc函数处理并返回。
函数的类型是string,RPC语言中string即C里面的一个字符串。所以上述函数有一个字符串作为参数传递,同时要返回字符串。即:
char ** test_1(char **argp, CLIENT *clnt) 和 char **test_1_svc(char **argp, struct svc_req *rqstp)

同理,如果声明是这样的:
program RDICTPROG  /* name of remote program ( not used ) */
{
    version RDICTVERS  /* declaration of version ( see below ) */
    {
        int INITW ( void )     = 1;  /* first procedure in this program */
        int INSERTW ( string ) = 2;  /* second procedure in this program */
        int DELETEW ( string ) = 3;  /* third procedure in this program */
        int LOOKUPW ( string ) = 4;  /* fourth procedure in this program */
    } = 1;  /* definition of the program version */
} = 0x30090949;  /* remote program number ( must be unique ) */
则说明这个RPC中有四个函数可用,即客户端可以调用initw_1、insertw_1、deletew_1、lookupw_1四个函数来向服务端发送消息,服务端可以用initw_1_svc、insertw_1_svc、deletew_1_svc、lookupw_1_svc四个函数来处理请求并返回结果。

原任务
假设现在有这样一个程序,源代码如下:
/* dict.c -- main, initw, nextin, insertw, deletew, lookupw */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXWORD 50        /* maximum length of a command or word */
#define DICTSIZ 100        /* maximum number of entries in dictionary. */
char dict[DICTSIZ][MAXWORD + 1];    /* storage for a dictionary of words */
int nwords = 0;            /* number of words in the dictionary */
/* 函数原型 */
int nextin(char *cmd, char *word);
int initw(void);
int insertw(const char *word);
int deletew(const char *word);
int lookupw(const char *word);
/* ------------------------------------------------------------------
* main -- insert, delete, or lookup words in a dictionary as specified
* ------------------------------------------------------------------ */
int main(int argc, char *argv[])
{
    char word[MAXWORD + 1];    /* space to hold word from input line */
    char cmd;
    int wordlen;        /* length of input word */
    printf("Please input:\n");
    while (1) {
    wordlen = nextin(&cmd, word);
    if (wordlen < 0) {
        exit(0);
    }
    switch (cmd) {
    case 'I':        /* 初始化 */
        initw();
        printf("Dictionary initialized to empty.\n");
        break;
    case 'i':        /* 插入 */
        insertw(word);
        printf("%s inserted.\n", word);
        break;
    case 'd':        /* 删除 */
        if (deletew(word)) {
        printf("%s deleted.\n", word);
        } else {
        printf("%s not found.\n", word);
        }
        break;
    case 'l':        /* 查询 */
        if (lookupw(word)) {
        printf("%s was found.\n", word);
        } else {
        printf("%s was not found.\n", word);
        }
        break;
    case 'q':        /* 退出 */
        printf("Program quits.\n");
        exit(0);
        break;
    default:        /* 非法输入 */
        printf("command %c invalid.\n", cmd);
        break;
    }            /* end of switch */
    }                /* end of while */
    return 0;
}                /* end of main */

/* ------------------------------------------------------------------
* nextin -- read a command and(possibly) a word from the next input line
* ------------------------------------------------------------------ */
int nextin(char *cmd, char *word)
{
    int i, ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    *cmd = (char) ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    if (ch == '\n') {
    return (0);
    }
    i = 0;
    while (!isspace(ch)) {
    if (++i > MAXWORD) {
        printf("error: word too long.\n");
        exit(1);
    }
    *word++ = ch;
    ch = getc(stdin);
    }                /* end of while */
    *word = '\0';        /* 原来的代码这里有问题 */
    return i;
}                /* end of nextin */

/* ------------------------------------------------------------------
* initw -- initialize the dictionary to contain no words at all
* ------------------------------------------------------------------ */
int initw(void)
{
    nwords = 0;
    return 1;
}                /* end of initw */

/* ------------------------------------------------------------------
* insertw -- insert a word in the dictionary
* ------------------------------------------------------------------ */
int insertw(const char *word)
{
    strcpy(dict[nwords], word);
    nwords++;
    return (nwords);
}                /* end of insertw */

/* ------------------------------------------------------------------
* deletew -- delete a word from the dictionary
* ------------------------------------------------------------------ */
int deletew(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        nwords--;
        strcpy(dict[i], dict[nwords]);
        return (1);
    }
    }                /* end of for */
    return (0);
}                /* end of deletew */

/* ------------------------------------------------------------------
* lookupw -- look up a word in the dictionary
* ------------------------------------------------------------------ */
int lookupw(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        return (1);
    }
    }                /* end of for */
    return (0);
}                /* end of lookupw */

这是一个简单的字典程序,即程序运行起来以后维护着一个字典库,用户可以向里面添加词语,也可以查询或删除词语。
当然,这个程序只能在同一台主机上运行。程序整个运行过程中,只需要完成如下几个步骤:
A、接受用户输入;
B、分析用户输入决定是否进行下面的步骤:
    1、初始化数据库;
    2、向数据库添加词语;
    3、查询或删除词语

任务分解
大家可以想到,对于一个大型系统,比如需要有很多人维护这个系统的数据。象上面这样独立的程序就不适用了,需要做成分布式系统:
即一个服务器维护着数据库,任何客户端都可以接受用户请求,客户端分析用户命令后提交给服务器去处理。
所以我们可能会把程序分成两部分:
客户端:接受用户输入,并判断用户输入内容的正确性,向服务器提交数据,等服务器返回消息
服务器端:维护数据,接受客户端命令并执行后返回结果。
所以我们把上面这个程序分解成下面两部分:
/* dict1.c -- main, nextin */
#include <stdio.h>
#include <stdlib.h>
#define MAXWORD 50        /* maximum length of a command or word */
/* ------------------------------------------------------------------
* main -- insert, delete, or lookup words in a dictionary as specified
* ------------------------------------------------------------------ */
int main(int argc, char *argv[])
{
    char word[MAXWORD + 1];    /* space to hold word from input line */
    char cmd;
    int wordlen;        /* length of input word */
    printf("Please input:\n");
    while (1) {
    wordlen = nextin(&cmd, word);
    if (wordlen < 0) {
        exit(0);
    }
    switch (cmd) {
    case 'I':        /* 初始化 */
        initw();
        printf("Dictionary initialized to empty.\n");
        break;
    case 'i':        /* 插入 */
        insertw(word);
        printf("%s inserted.\n", word);
        break;
    case 'd':        /* 删除 */
        if (deletew(word)) {
        printf("%s deleted.\n", word);
        } else {
        printf("%s not found.\n", word);
        }
        break;
    case 'l':        /* 查询 */
        if (lookupw(word)) {
        printf("%s was found.\n", word);
        } else {
        printf("%s was not found.\n", word);
        }
        break;
    case 'q':        /* 退出 */
        printf("Program quits.\n");
        exit(0);
        break;
    default:        /* 非法输入 */
        printf("command %c invalid.\n", cmd);
        break;
    }            /* end of switch */
    }                /* end of while */
    return 0;
}                /* end of main */

/* ------------------------------------------------------------------
* nextin -- read a command and(possibly) a word from the next input line
* ------------------------------------------------------------------ */
int nextin(char *cmd, char *word)
{
    int i, ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    *cmd = (char) ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    if (ch == '\n') {
    return (0);
    }
    i = 0;
    while (!isspace(ch)) {
    if (++i > MAXWORD) {
        printf("error: word too long.\n");
        exit(1);
    }
    *word++ = ch;
    ch = getc(stdin);
    }                /* end of while */
    *word = '\0';
    return i;
}                /* end of nextin */


/* dict2.c -- initw, insertw, deletew, lookupw */
#include <string.h>
#define MAXWORD 50        /* maximum length of a command or word */
#define DICTSIZ 100        /* maximum number of entries in dictionary. */
char dict[DICTSIZ][MAXWORD + 1];    /* storage for a dictionary of words */
int nwords = 0;            /* number of words in the dictionary */
/* ------------------------------------------------------------------
* initw -- initialize the dictionary to contain no words at all
* ------------------------------------------------------------------ */
int initw(void)
{
    nwords = 0;
    return 1;
}                /* end of initw */

/* ------------------------------------------------------------------
* insertw -- insert a word in the dictionary
* ------------------------------------------------------------------ */
int insertw(const char *word)
{
    strcpy(dict[nwords], word);
    nwords++;
    return (nwords);
}                /* end of insertw */

/* ------------------------------------------------------------------
* deletew -- delete a word from the dictionary
* ------------------------------------------------------------------ */
int deletew(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        nwords--;
        strcpy(dict[i], dict[nwords]);
        return (1);
    }
    }                /* end of for */
    return (0);
}                /* end of deletew */

/* ------------------------------------------------------------------
* lookupw -- look up a word in the dictionary
* ------------------------------------------------------------------ */
int lookupw(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        return (1);
    }
    }                /* end of for */
    return (0);
}                /* end of lookupw */

这两部分代码只是在功能上实现了分离,显然实现通讯的部分还没有,下面我们利用RPC来快速实现通讯。

利用RPC实现分布式系统
首先,建立一个RPC源文件,源代码rdict.x如下:
/* rdict.x */
/* RPC declarations for dictionary program */
const MAXWORD = 10;   /* maximum length of a command or word */
const DICTSIZ = 3;  /* number of entries in dictionary */
struct example      /* unused structure declared here to */
{
    int  exfield1;  /* illustrate how rpcgen builds XDR */
    char exfield2;  /* routines to convert structures */
};
/* ------------------------------------------------------------------
* RDICTPROG -- remote program that provides insert, delete, and lookup
* ------------------------------------------------------------------ */
program RDICTPROG  /* name of remote program ( not used ) */
{
    version RDICTVERS  /* declaration of version ( see below ) */
    {
        int INITW ( void )     = 1;  /* first procedure in this program */
        int INSERTW ( string ) = 2;  /* second procedure in this program */
        int DELETEW ( string ) = 3;  /* third procedure in this program */
        int LOOKUPW ( string ) = 4;  /* fourth procedure in this program */
    } = 1;  /* definition of the program version */
} = 0x30090949;  /* remote program number ( must be unique ) */

然后用下列命令产生服务器端函数rdict_srv_func.c:
rpcgen -Ss -o rdict_srv_func.c rdict.x
然后用下列命令产生客户端程序rdict_client.c:
rpcgen -Sc -o rdict_client.c rdict.x
/************关于本文档********************************************
*filename: 我是这样学习Linux下C语言编程的-利用RPC快速实现分布式系统
*purpose: 说明如何利用RPC快速进行客户端-服务器端C-S结构编程
*wrote by: zhoulifa(zhoulifa@163.com) 周立发(http://zhoulifa.bokee.com)
Linux爱好者 Linux知识传播者 SOHO族 开发者 最擅长C语言
*date time:2007-02-27 19:20
*Note: 任何人可以任意复制代码并运用这些文档,当然包括你的商业用途
* 但请遵循GPL
*Thanks to:
*                Ubuntu 本程序在Ubuntu 6.10系统上测试完全正常
*                Google.com 我通过google搜索并参考了RPC编程相关的许多文章
*               网络安全焦点(www.xfocus.net) 我主要借鉴了此文 http://www.xfocus.net/articles/200009/10.html
*Hope:希望越来越多的人贡献自己的力量,为科学技术发展出力
* 科技站在巨人的肩膀上进步更快!感谢有开源前辈的贡献!
*********************************************************************/
然后用下列命令产生Makefile:
rpcgen -Sm rdict.x > Makefile

Makefile文件原内容如下:
# This is a template Makefile generated by rpcgen

# Parameters

CLIENT = rdict_client
SERVER = rdict_server

SOURCES_CLNT.c =
SOURCES_CLNT.h =
SOURCES_SVC.c =
SOURCES_SVC.h =
SOURCES.x = rdict.x

TARGETS_SVC.c = rdict_svc.c   rdict_xdr.c
TARGETS_CLNT.c = rdict_clnt.c   rdict_xdr.c
TARGETS = rdict.h rdict_xdr.c rdict_clnt.c rdict_svc.c    

OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o)
OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o)
# Compiler flags

CFLAGS += -g
LDLIBS += -lnsl
RPCGENFLAGS =

# Targets

all : $(CLIENT) $(SERVER)

$(TARGETS) : $(SOURCES.x)
        rpcgen $(RPCGENFLAGS) $(SOURCES.x)

$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c)

$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c)

$(CLIENT) : $(OBJECTS_CLNT)
        $(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS)

$(SERVER) : $(OBJECTS_SVC)
        $(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)

clean:
         $(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER)

动手修改Makefile,修改后内容如下:
# This is a template Makefile generated by rpcgen

# Parameters

CLIENT = rdict_client
SERVER = rdict_server

SOURCES_CLNT.c =
SOURCES_CLNT.h =
SOURCES_SVC.c =
SOURCES_SVC.h =
SOURCES.x = rdict.x

TARGETS_SVC.c = rdict_svc.c   rdict_xdr.c rdict_srv_func.c
TARGETS_CLNT.c = rdict_clnt.c   rdict_xdr.c rdict_client.c
TARGETS = rdict.h rdict_xdr.c rdict_clnt.c rdict_svc.c

OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o)
OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o)
# Compiler flags

CFLAGS += -g
LDLIBS += -lnsl
RPCGENFLAGS =

# Targets

all : $(CLIENT) $(SERVER)

$(TARGETS) : $(SOURCES.x)
        rpcgen $(RPCGENFLAGS) $(SOURCES.x)

$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c)

$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c)

$(CLIENT) : $(OBJECTS_CLNT)
        $(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS)

$(SERVER) : $(OBJECTS_SVC)
        $(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)

clean:
         $(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER) *~

修改客户端源代码rdict_client.c,把接受用户输入并分析用户输入内容的部分加到程序中来。修改后的代码为:
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/

#include "rdict.h"

/* ------------------------------------------------------------------
* nextin -- read a command and(possibly) a word from the next input line
* ------------------------------------------------------------------ */
int nextin(char *cmd, char *word)
{
    int i, ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    *cmd = (char) ch;
    ch = getc(stdin);
    while (isspace(ch)) {
    ch = getc(stdin);
    }                /* end of while */
    if (ch == EOF) {
    return (-1);
    }
    if (ch == '\n') {
    return (0);
    }
    i = 0;
    while (!isspace(ch)) {
    if (++i > MAXWORD) {
        printf("error: word too long.\n");
        exit(1);
    }
    *word++ = ch;
    ch = getc(stdin);
    }                /* end of while */
    *word = '\0';
    return i;
}                /* end of nextin */

void rdictprog_1(char *host)
{
    CLIENT *clnt;
    int *result_1;
    char *initw_1_arg;
    int *result_2;
    char *insertw_1_arg;
    int *result_3;
    char *deletew_1_arg;
    int *result_4;
    char *lookupw_1_arg;

#ifndef    DEBUG
    clnt = clnt_create(host, RDICTPROG, RDICTVERS, "udp");
    if (clnt == NULL) {
    clnt_pcreateerror(host);
    exit(1);
    }
#endif                /* DEBUG */
    char word[MAXWORD + 1];    /* space to hold word from input line */
    char cmd;
    int wordlen;        /* length of input word */
    while (1) {
    printf("\nPlease input:");
    wordlen = nextin(&cmd, word);
    if (wordlen < 0) {
        exit(0);
    }
    /* printf("\nYour cmd is:%c, your word is:%s\n", cmd, word); */
    switch (cmd) {
    case 'I':        /* 初始化 */
        result_1 = initw_1((void *) &initw_1_arg, clnt);
        /* printf("\nYour result is:%d\n", *result_1); */
        if (result_1 == (int *) NULL)
        clnt_perror(clnt, "call failed");
        else
        if(*result_1 ==0) printf("Dictionary initialized to empty.\n");
        else printf("Dictionary have already initialized.\n");
        break;
    case 'i':        /* 插入 */
        insertw_1_arg = word;
        result_2 = insertw_1(&insertw_1_arg, clnt);
        /* printf("\nYour result is:%d, your string is:%s(%d)\n", *result_2, insertw_1_arg, strlen(insertw_1_arg)); */
        if (result_2 == (int *) NULL)
        clnt_perror(clnt, "call failed");
        else
        printf("%s inserted.\n", word);
        break;
    case 'd':        /* 删除 */
        deletew_1_arg = word;
        result_3 = deletew_1(&deletew_1_arg, clnt);
        /* printf("\nYour result is:%d, your string is:%s(%d)\n", *result_3, deletew_1_arg, strlen(deletew_1_arg)); */
        if (result_3 == (int *) NULL)
        clnt_perror(clnt, "call failed");
        else
        printf("%s deleted.\n", word);
        break;
    case 'l':        /* 查询 */
        lookupw_1_arg = word;
        result_4 = lookupw_1(&lookupw_1_arg, clnt);
        /* printf("\nYour result is:%d, your string is:%s(%d)\n", *result_4, lookupw_1_arg, strlen(lookupw_1_arg)); */
        if (result_4 == (int *) NULL)
        clnt_perror(clnt, "call failed");
        else
        if(*result_4 ==0) printf("%s found.\n", word);
        else printf("%s not found.\n", word);
        break;
    case 'q':        /* 退出 */
        printf("Program quits.\n");
        exit(0);
        break;
    default:        /* 非法输入 */
        printf("Command %c(%s) invalid.\n", cmd, word);
        break;
    }            /* end of switch */
    }                /* end of while */

#ifndef    DEBUG
    clnt_destroy(clnt);
#endif                /* DEBUG */
}


int main(int argc, char *argv[])
{
    char *host;

    if (argc < 2) {
    printf("usage: %s server_host\n", argv[0]);
    exit(1);
    }
    host = argv[1];
    rdictprog_1(host);
    exit(0);
}

同时修改服务器端代码rdict_srv_func.c,修改后内容为:
/*
* This is sample code generated by rpcgen.
* These are only templates and you can use them
* as a guideline for developing your own functions.
*/

#include "rdict.h"

char dict[DICTSIZ][MAXWORD + 1];    /* storage for a dictionary of words */
int nwords = 0;            /* number of words in the dictionary */
char init_bool = 0;

int initw(void)
{
    if(init_bool) return 1;
    nwords = 0;
    init_bool = 1;
    return 0;
}                /* end of initw */

/* ------------------------------------------------------------------
* insertw -- insert a word in the dictionary
* ------------------------------------------------------------------ */
int insertw(const char *word)
{
    strcpy(dict[nwords%DICTSIZ], word);
    nwords++;
    return (nwords);
}                /* end of insertw */

/* ------------------------------------------------------------------
* deletew -- delete a word from the dictionary
* ------------------------------------------------------------------ */
int deletew(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        nwords--;
        strcpy(dict[i], dict[nwords]);
        return (1);
    }
    }                /* end of for */
    return (0);
}                /* end of deletew */

/* ------------------------------------------------------------------
* lookupw -- look up a word in the dictionary
* ------------------------------------------------------------------ */
int lookupw(const char *word)
{
    int i;
    for (i = 0; i < nwords; i++) {
    if (strcmp(word, dict[i]) == 0) {
        return 0;
    }
    }                /* end of for */
    return 1;
}                /* end of lookupw */

int *initw_1_svc(void *argp, struct svc_req *rqstp)
{
    static int result;

    /*
     * insert server code here
     */

    result = initw();

    return &result;
}

int *insertw_1_svc(char **argp, struct svc_req *rqstp)
{
    static int result;

    /*
     * insert server code here
     */
    result = insertw(*argp);

    return &result;
}

int *deletew_1_svc(char **argp, struct svc_req *rqstp)
{
    static int result;

    /*
     * insert server code here
     */

    result = deletew(*argp);

    return &result;
}

int *lookupw_1_svc(char **argp, struct svc_req *rqstp)
{
    static int result;

    /*
     * insert server code here
     */

    result = lookupw(*argp);

    return &result;
}

至此,程序做好了。输入一个make命令就可以生成test_server和test_client这两个可执行程序了。
在一台机器上运行./test_server程序,在另外的客户机上运行./test_client server_ip就可以了。这里server_ip是运行着test_server程序的主机的IP地址。

阅读全文
  nginx现在正在以光的速度蔓延开来,他以其稳定性和高性能等众多优点迅速扩大市场,大家都知道,nginx是以单线程为基础的,那么他怎么能在并发性上取得优势的呢?会不会因为网络阻塞而导致主线程阻塞呢?下面就相关问题作一些概念性的阐述。
阅读全文
程序员世界里有哪些名言警局呢?Jun Auza 列出了一些启迪人心的至理名言,它们大多来自产业界富于经验的人们。
下文列出前10个供读者欣赏。

10. "People think that computer science is the art of geniuses but the actual reality is the opposite, just many people doing things that build on each other, like a wall of mini stones."- Donald Knuth

10. “人们认为计算机科学是天才的艺术,但事实完全相反:只是很多人在共同建立起来的事物之上工作,就像一条由小石头铺成的小径。”—— Donald Knuth

9. “First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack.”- George Carrette

9. “首先学会计算机科学和所有的理论。然后发展出一个编程风格。之后便要忘掉所有这些,以自由的方式探索。”—— George Carrette

8. “Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris.”- Larry Wall

8. “大多数的你们都熟悉程序员的美德。它们有三点:懒,不耐烦,以及狂妄自大。”—— Larry Wall

7. “Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other,with no structural integrity, but just done by brute force and thousands of slaves.”- Alan Kay

7. “今日的大多数软件很像埃及金字塔,由千百万砖头堆砌起来,层层相切,没有着整体的结构,是由畜力和成千上万奴隶的力量建立起来的。”—— Alan Kay

6. “The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”- Seymour Cray

6. “程序员的问题是,不到太晚,你永远无法知道一个他在做着些什么。”—— Seymour Cray

5. “To iterate is human, to recurse divine.”- L. Peter Deutsch

5. “人理解迭代,神理解递归。”—— Peter Deutsch

4. "On two occasions I have been asked [by members of Parliament]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."- Charles Babbage

4. “有两次我被(国会议员)问道:‘ Mr. Babbage,如果你输入计算机错误的数据,正确的答案会出来吗?’我完全无法理解能产生此种问题的大脑的混乱。”

3. "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."- Linus Torvalds

3. “大部分好的程序员编程并不是为了钱或名望,而只是因为纯粹的乐趣。”—— Linus Torvalds

2. "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."- Martin Golding

2. “编程的时候,总是想着那个维护你代码的人会是一个知道你住在哪儿的有暴力倾向的精神病患者。”—— Martin Golding

1. “There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”- C.A.R. Hoare

1. “有两种生成一个软件设计方案的途径。一个是把它做得如此简单,以致于明显不会有漏洞存在。另一个是把它做的如此复杂,以致于不会有明显的漏洞存在。”—— C.A.R. Hoare


来源:http://cnbeta.com/articles/129807.htm