Archive for February, 2006

关于.net2.0和SQLServer2005

.net2.0和SQLServer2005被微软融合到一起,让开发者更加容易使用。不过时间有限,还没有好好去研究和尝试。

昨天有朋友来家玩,告诉我一个.net2.0和SQLServer2005之间完美融合的例子。SQLServer2005的存储过程已经直接被SQLServer2005包装成了Web Service,也就是说,任何想通过调用存储过程取得数据的实现,都可以直接调用Web Service来获取。这样就分离了数据层和业务层实现,接口用Web Service封装,确实是个很不错的东西。

目前的很多系统在实现以上功能时,一般都采用socket,甚至有些根本不设计接口,直接操作原数据。socket调用的确很不错,但如果接口数量巨大,那么接口的设计和实现的工作量也巨大。有了SQLServer2005这样的集成Web Service机制,开发起来应该是非常快速的。

唯一的遗憾是SQLServer2005不支持Unix、Linux、BSD系统,.net也不能跨平台。

Leave a Comment

Compiler error message confusion

    昨天写代码时,发现一个很有趣的事。
    我在一个头文件(全是一些结构体的定义)的最后一个结构定义的结尾少写了一个;号
结果用cc编译的时候报了n多的错误,提示在紧跟该头文件的下一行(该行可能在当前文件或include文件中的有效程序行)位置错,描述如下:
“xxx.c”, line 6: error: syntax error, probably missing “,”, “;” or “=”
并同时在下面还引申出来若干的错误。
    当时没有意识到是头文件的错,就找啊找啊,找了很久也没有找到错在哪里,后来通过跟备份目录一个文件一个文件的比较才知道的。
    通过这个错误,感到cc编译器有时候的错误提示不太友好。
比如这个同样的错误,在dev-c++中编译就只是报一个错,并告诉你是在那一行的前面错了,而不是那一行错。
syntax error before “int”
而在gcc下的报的错,则与cc类似,但也有before这个词汇。
xxx.c:6: error: syntax error before ‘int’
同样的错误在vc6下报错为:
xxx.cpp(6) : error C2144: syntax error : missing ‘;’ before type ‘int’

Leave a Comment

About fork

fork()用于UNIX下面创建子进程。用fork()创建的子进程将完全复制父进程的数据空间、堆、栈,但父子进程不共享这些存储空间。

fork()执行成功之后,会对子进程和父进程分别返回值,给子进程的返回值是0,给父进程的返回值是子进程的pid。

当然,子进程不会跟父进程同时结束,即使父进程已经结束,子进程仍然可以做它的事情。


// fork.c
// 执行过程中可以用ps -u username来观察进程的状态
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>

static void process1();
static void process2();

int main()
{
    // 开启两个子进程
    pid_t pid;
    if ((pid=fork()) == 0)
    {
        process1();
        _exit(0);
    }
    else if(pid>0)
    {
        sleep(2);
    }
    if ((pid=fork()) == 0)
    {
        process2();
        _exit(0);
    }
    else if(pid>0)
    {
        sleep(2);
    }
}

static void process1()
{
    fprintf(stderr, "child1 running...\n");
    fprintf(stderr, "parent pid = %d\n", getppid());
    sleep(25);
    fprintf(stderr, "child1 is over.\n");
}

static void process2()
{
    fprintf(stderr, "child2 running...\n");
    fprintf(stderr, "parent pid = %d\n", getppid());
    sleep(10);
    fprintf(stderr, "child2 is over.\n");
}

Unix编程书上介绍的fork处理进制是用switch实现。

pid_t pid;
switch(pid=fork())
{
case -1:
    fprintf(stderr, "fork error\n");
case 0:
    // 子进程代码
default:
    // 父进程代码
}

Unix编程书上介绍的fork处理进制是用switch实现。 

Leave a Comment

Top 10 Linux console applications

呵呵,除了Lynx和MySQL,其它都没有摸过,不过作者指的是Linux系统管理员常用工具,我的水平还很菜啊。

  1. Screen
  2. Pine
  3. Lynx
  4. Zed
  5. Oleo
  6. TPP
  7. MySQL
  8. Midnight Commander
  9. ZGV
  10. Nethack

原文出处:http://applications.linux.com/article.pl?sid=05/04/20/2235237&tid=13&tid=86&tid=47

Leave a Comment