一些Linux c、c++ 小基础

#### linux man page

https://www.kernel.org/doc/man-pages/

http://linux.die.net/man/

https://www.linux.com/learn/docs/ldp/624-Man-Page

  https://wiki.archlinux.org/index.php/Man_page_(简体中文)

 

 

LINUX 环境变量总结

http://blog.csdn.net/ddviplinux/article/details/4280433

1. vim /etc/profile  (持久化)所有用户都有权利访问
2. vim /root/.bashrc  (持久化)可以控制用户权限
3. export XX 当前shell

export abc="myNameisABC"

echo $abd



4.C 语言  getenv(); setenv(); unsetenv();
http://www.cplusplus.com/reference/cstdlib/getenv/

 

 

 

=======================

使用socket时,程序关闭了,但是port还没有关闭,

 

再次运行此程序会提示:

hy@hy-ThinkPad-T60:~/shareFolder/test/practice$ ./libevent_Server
 server socket Test   port(40713)   pid = 1691  , uid=1000 , gid =1000
 bind: Address already in use

hy@hy-ThinkPad-T60:~/shareFolder/test/practice$ netstat -anp | grep 40713
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:40713           0.0.0.0:*               LISTEN      1611/libevent_Serve
tcp        0      0 192.168.1.254:40713     192.168.1.254:33017     ESTABLISHED 1611/libevent_Serve
tcp       57      0 192.168.1.254:33017     192.168.1.254:40713     ESTABLISHED 1673/clent

可以看到端口依然没有关闭,只能重启么?

 


    //http://blog.chinaunix.net/uid-20532339-id-1931823.html
    //http://www.cnblogs.com/qq78292959/archive/2012/03/22/2411387.html
    //http://www.cnblogs.com/qq78292959/archive/2013/01/18/2865926.html
    int bReuseaddr=1;//1
    setsockopt(listener, SOL_SOCKET , SO_REUSEADDR,(char *)&bReuseaddr, sizeof(bReuseaddr));
       

 

找了一些方案。。

 =========================================

 

register 希望变量放在寄存器中,方便循环调用。更快。

voliate 多变的,说明这个变量,可能被多个线程使用,,每次调用前,需要重新读取,(而不是直接取过去缓存在寄存器中的值)

--------------------------

extern int func1(int i); //支持外部链接

static int func2(int i);//不支持外部链接, 只能在定义函数的内部调用此函数。  (但是 使用函数指针,可以通过调用参数为func2的  func4方法,来调用static func2(); 或者你写个funcA 去调用func2也行。  )

 int func3(int i);//默认支持外部链接

--------------------------

const 也是。(凡事都没有那么绝对!)

mutable的含义在这里表示这个变量可以在const中被修改,它overwrite了const修饰。

 

===================================

7.3.1

exit和_exit函数
exit和_exit函数用于正常终止一个程序:_exit立即进入内核exit则先执行一些清除处理
(包括调用执行各终止处理程序,关闭所有标准 I / O流等),然后进入内核。

 

==================================

c中不用goto, 转功能的函数用setjmp, longjmp    (unsafe thread)

编译器千万别优化,

1.未优化: g++ classA.cpp

2.优化:  g++ -o classA.cpp ()

==========================================

posted @ 2013-07-05 22:34  scott_h  阅读(352)  评论(0编辑  收藏  举报