write a shell in c

源文章标题取得很大,write a shell in c。相关的内容总结如下。

  • fork(), exec() and waitpid() are defined by the POSIX standard, and Windows is not POSIX-compliant. In order to have POSIX compliance under Windows, you should compile under Cygwin.

  • fork, exec, chdir are in unistd.h(unix std); execvp is in stdlib

  • system命令相当于 fork + exec + waitpid

  • windows也提供了一个chdir函数,叫_chdir,在direct.h里

  • cc来自于Unix的c语言编译器,是 c compiler 的缩写。gcc来自Linux世界,是GNU compiler collection 的缩写,注意这是一个编译器集合,不仅仅是c或c++

  • strtok()

    1
    2
    3
    4
    5
    6
    char sentence[]="192.168...9...14";
    char *token=strtok(sentence,".");
    while(token!=NULL){
    cout<<token<<" ";
    token=strtok(NULL,".");
    }
  • 在gcc编译器中,对标准库进行了扩展,加入了一个getline函数。会自动malloc, realloc,所以用的话,需要自己手动free,好像没啥人用,参考这里

  • 我用system代替了fork等,于是有了window版