工作中遇到的问题总结

  1. HTTP协议中,报文头部 Content-Length 指的是 空行之后内容的长度。比如下面的报文:

POST /submitdata/service.asmx/g_Submit HTTP/1.1
Host: cf.51welink.com
Content-Type: application/x-www-form-urlencoded
Content-Length: length

sname=string&spwd=string&scorpid=string&sprdid=string&sdst=string&smsg=string

  Content-Length 的长度是 strlen("sname=string&spwd=string&scorpid=string&sprdid=string&sdst=string&smsg=string") 的返回值。

  3. telent 命令

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

  telent www.shouxiner.com 80

  Trying 198.168.11.254 ...

  Connected to localhost.

  Escape character is .

  GET / index.html HTTP/1.1

  Host : www.shouxiner.com

  HTTP/1.1 200 OK

  Date : Sun, 01 Oct 2000 23:25:17 GMT

  Server : Apache/1.3.11 BSafe-SSL/1.38 (Unix) FrontPage/4.0.4.3

  Last-Modified: Tue, 04 Jul 2000 09:46:21 GMT

  ......

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

  curl -d 可以输入post 参数

  6. installation parttern of php extension (php拓展安装模式)

phpize
./configure
make 
sudo make install

  7. pv命令的使用 & pv命令源码分析

  8. Linux 管道符 与 重定向的区别

  |  >  <  >>  <<

  9. QoS 学习

  https://en.wikipedia.org/wiki/Quality_of_service#Standards

  

  10. 查看U盘

  查看 linux 插入的U盘,必须有管理员权限: sudo fdisk -l 或者 su && fdisk -l

  11. 手动配置网卡

  vi /etc/sysconfig/network-scripts/ifcfg-eth0

  配置完以后 重启网络

  service network restart  或  /etc/init.d/network restart

  12. 翻译C++ reference

  http://www.cplusplus.com/reference/algorithm/count/?kw=count

  http://www.cplusplus.com/reference/algorithm/find/?kw=find

  http://www.cplusplus.com/reference/algorithm/lower_bound/?kw=lower_bound

  http://www.cplusplus.com/reference/algorithm/upper_bound/?kw=upper_bound

  13. Linux平台内存泄漏检测工具 - valgrind

  

  14. time 工具

  time 工具 用于初步分析程序性能很有用,real 项就是程序执行的时间,user 项就是程序在用户态 cpu 时间,sys 表示内核态 CPU 的时间。real - user - sys 不一定等于 0,这正好是程序 IOwait 的时间。——韩天峰

  

  16. 保护进程不被中断:nohup / screen / supervisor(python编写) / & 操作符

  nohup 命令

$ nohup ./binTreeTravel 
nohup: ignoring input and appending output to ‘nohup.out’

  输出被重定向并 append 到 nohup.dat

$ nohup ./binTreeTravel > output.dat
nohup: ignoring input and redirecting stderr to stdout

  输出被重定向并 append 到 output.dat 文件。

  17. cat 和 head 命令辨析

  18. Q:禁用COOKIE 后 SEESION 还能用吗?

  A: session是在服务器端保持用户会话数据的一种方法,对应的cookie是在客户端保持用户数据。HTTP协议是一种无状态协议,服务器响应完之后就失去了与浏览器的联系,最早,Netscape将cookie引入浏览器,使得数据可以客户端跨页面交换,那么服务器是如何记住众多用户的会话数据呢? 首先要将客户端和服务器端建立一一联系,每个客户端都得有一个唯一标识,这样服务器才能识别出来。建议唯一标识的方法有两种:cookie或者通过GET方式指定。默认配置的PHP使用session的时会建立一个名叫”PHPSESSID”的cookie(可以通过php.ini修改session.name值指定),如果客户端禁用cookie,你也可以指定通过GET方式把session id传到服务器(修改php.ini中session.use_trans_sid等参数)。<a href=”p.php?<?php print session_name() ?>=<?php print session_id() ?>”>xxx</a>,也可以通过POST来传递session值.

  19. ps 命令 -ef 选项和 aux 选项的区别

$ ps -ef | head -2   
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Dec17 ?        00:00:07 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
$ ps aux | head -2
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  57696  6772 ?        Ss   Dec17   0:07 /usr/lib/systemd/systemd --switched-root --system --deserialize 24

  20. nc 命令、type命令、locate 命令、updatedb 命令

  21. php-fpm 调整进程数以节省内存

  http://levi.yii.so/archives/3200

  http://segmentfault.com/a/1190000000630270

  22. APUE open lseek 和 write 的原子调用问题

  open (... | O_APPEND...)  

  23. parallel 命令 并行地执行命令

  24. man

  man 2 write 

  man 3 是 lib 的

  25. PHP 解决 跨子域问题

   http://blog.csdn.net/veverrr/article/details/7079348

当访问a.sso.com时,则将通过 

 session_start();
  $_SESSION['person'] = "SBSBSBS";
  $session_id = session_id();
 setcookie('name',$session_id,time()+3600*24,'/','SSO.com');

  将session_id 保存在cookie中。

由于在PHP中,session是一个数组,PHP有 serialize() 函数,将数组序列化

$session_value = serialize($_SESSION);
 

然后将$session_value 保存在数据库中。


在访问b.sso.com时,则从cookie中获取到session_id,然后到数据库中根据session_id将 经过序列化过的session 获取出来

接着就可以对该session进行操作,实现session 跨子域。

 

由于将session保存在数据库中,存取都是比较费时的操作,因此可以将session保存在缓存中,例如memcached 或者redis中,

这样对session的存取操作就比较快速了。

使用缓存还有个好处就是,通常session有一定得存活时间,如果存在数据库中,还需要保存该session的存活时间,在取出session时,还需要判断其是否失效。

使用缓存存放session就可以在存放的时候设置其存活时间,减少了取出后的失效判断这一个过程。
View Code

   session_id() || session_start(); // 如果 session_id() 返回 FALSE , 执行 session_start() ; 如果 session_id() 返回 string , 就执行下面的代码——或运算符的性质 

  26. C++ 中 unsigned int 等价于 unsigned

  http://en.cppreference.com/w/cpp/language/types

  27 CentOS install xfce

# yum install epel-release
# yum groupinstall "X Window system"
# systemctl isolate graphical.target
$ yum groupinfo xfce
# yum groupinstall xfce
# systemctl isolate graphical.target

   http://wenku.baidu.com/link?url=BLpSzJFFYmmeOk0c6kvQYtFI-HKXQHbQKQI7K-JaUGww9VsQV0UwkMzk1MYqBCFONrRfSg3XCA2T5zpKnybV9nYGLa_PhCmuTrQ716SCW6O

  http://blog.csdn.net/smstong/article/details/44802989#32-安装x-window-system

  28. ubuntu 开启 22端口 —— 开启SSH服务

  http://www.cnblogs.com/nodot/archive/2011/06/10/2077595.html

  29. 基于数据库的抢购系统设计

  利用MySQL update 操作的原子性,预先设定 一定数量的 token ,当有用户第一次下单时,执行 SQL 如下:

UPDATE table_name SET token=1 where token=0 and ......

  30. C++ 迭代器深入理解

  http://www.cplusplus.com/reference/iterator/BidirectionalIterator/

  31. “并发、并行、异步、阻塞” 等网络通信模型,彻底弄清。

  32. 线程获得时间片并访问到了加锁的资源时,线程会挂起等待吗?

  线程与多处理机的关系:
  On a multiprocessor or multi-core system, multiple threads can be executed in parallel (at the same instant), with every processor or core executing a separate thread simultaneously; on a processor or core with hardware threads, separate software threads can also be executed concurrently by separate hardware threads. —— from Wikipedia
  定义:
  1. 多处理机(multi-processing)
  Multiprocessing is the use of two or more CPUs within a single computer system. —— from Wikipedia
  2. 线程(thread)
  Multiple threads can exist within the same process, executing concurrently (one starting before others finish) and share resources such as memory, while different processes do not share these resources. —— from Wikipedia

    从以上内容可以推断,在多处理机系统中,当多个线程访问到同一个加锁的资源时,线程会等待其读 / 写锁被解除。尤其是当某线程获得时间片,访问到加锁的资源时,线程也是需要等待的。

  这也就解释了,为什么不合理的锁会降低程序性能。(相关问题:《剑指Offer》 2.2 面试题2 ”实现 Single 模式“)
  see also
  https://en.wikipedia.org/wiki/Thread_(computing)#Thread_and_fiber_issues
  https://en.wikipedia.org/wiki/Multiprocessing

  33. baidu实习岗 内推竞聘 技术笔试

  i. 尽可能多的说出所使用的语言的几种内建类型。

  i. 栈和队列的区别,分别说出它们的一种应用场景。

  i. 是否熟悉 linux 和 vim。

  i. 线程与进程的区别,同步与异步的区别。具体解释异步。

  i. N * N 的矩阵里面,矩阵元素都是整形,设计算法,取得矩阵当中最大的 N 个元素。

  34. mysql报错:ERROR 1045 (28000)

  解决方案:i.停止 mysql 服务进程

       i. mysqld_safe --user=mysql --skip-grant-tables &

       i. 再次正常地进入mysql : mysql -u root -p

       i. use mysql , 修改 user 表用户密码或者host——取决于具体引发 error 的原因。

  参考链接:http://blog.sina.com.cn/s/blog_a7cf995a0101azwg.html

       https://www.baidu.com/baidu?tn=monline_3_dg&ie=utf-8&wd=ERROR+1045+%2828000%29

  35. 抖动-操作系统

  在计算机操作系统的抖动,又叫颠簸。如果分配给进程的存储块数量小于进程所需要的最小值,进程的运行将很频繁地产生缺页中断,这种频率非常高的页面置换现象称为抖动。在请求分页存储管理中,可能出现这种情况,即对刚被替换出去的页,立即又要被访问。需要将它调入,因无空闲内存又要替换另一页,而后者又是即将被访问的页,于是造成了系统需花费大量的时间忙于进行这种频繁的页面交换,致使系统的实际效率很低,严重导致系统瘫痪,这种现象称为抖动现象。

  http://baike.baidu.com/view/1500530.htm

  36. 磁盘管理与维护

  df -h 命令查看磁盘占用情况

  du -sh 显示目录或文件占用磁盘空间    

  37. mysql InnoDB 优化配置

innodb_file_per_table=1 //修改InnoDB为独立表空间模式,每个数据库的每个表都会生成一个数据空间
# log-bin=mysql-bin  //注释掉该选项,不然自动记录操作日志(用于主从同步)
View Code

  reference: http://blog.csdn.net/gaoxuefeng/article/details/7699400  

  38. mysql 命令 show processlist 会展示出线程的的几种状——sleep、query end 等等

  39. 在代码目录下查找文件中包含关键字的 grep 命令。一定要有表示(当前)路径的 . (点)

grep -R|-r -n 'function static_version' . | grep -v .svn

   -r, -R 递归

  -v 排除(原文: -invert-match——匹配反转)

  -n 行号

  -l 只显示文件名,会停止在第一个匹配项

  

  40. ssh 客户端禁用 ctrl + s 设置。

  在远端主机上修改用户的 .bashrc 文件

vim ~/.bashrc

# disable ctrl + s
stty ixany
stty ixoff -ixon
View Code

   41. Linux 硬件资源管理

  lspci,

  more /proc/cpuinfo,

  more /proc/meminfo,

  fdisk -l

  42. 网络管理

  netstat -lntp 列出状态为 listen 且 tcp 连接的端口

  43. vim + ctags

  i.命令行执行

alias phptags='ctags --langmap=php:.engine.inc.module.theme.php --php-kinds=cdf --languages=php -R .'

  i. vim ~/.ctags

--regex-php=/^[ 	]*[(private|public|static)( 	)]*function[ 	]+([A-Za-z0-9_]+)[ 	]*(/1/f, function, functions/
--regex-php=/^[ 	]*[(private|public|static)]+[ 	]+$([A-Za-z0-9_]+)[ 	]*/1/p, property, properties/
--regex-php=/^[ 	]*(const)[ 	]+([A-Za-z0-9_]+)[ 	]*/2/d, const, constants/

  i. 执行 phptags

  参考:http://www.epooll.com/archives/829/

  44.编译原理入门:网上流传较广的一篇《编译原理学习导论》(作者四川大学唐良)

  45. vim 自动补全默认支持 PHP

  To enable PHP autocomplete every time you open a PHP file, add this to your ~/.vimrc; 

autocmd FileType php set omnifunc=phpcomplete 

  46. To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it.

sudo usermod -aG docker your_username

   Start the docker daemon at boot

sudo chkconfig docker on

  47. mysql 命令附加参数,非交互式地执行 sql 语句。其执行结果直接写到文件中

mysql -h 10.48.55.128 -P 8005 -u map -p place_waimai_boye -e "show tables" > place_waimai_boye.tables.sql

   查询数据库数据量大小

use information_schema;

#比如查看数据库home的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';

  reference : http://www.frostsky.com/2011/08/mysql-query-size/

  48. 使 ~/.bash_profile 文件生效

source ~/.bash_profile

  49. .sock 文件是什么?

        在搭建LNMP环境时,我经常会看到各种 .sock 文件,比如安装 MySQL 时,会有 /tmp/MySQL.sock; nginx 与 php-fpm(fastCGI) 来连接。

        查资料得知: .sock 类型文件是采用 unix domain socket 套接字连接时产生的文件,当然也可以不指定后缀名。比如 http://blog.chinaunix.net/uid-26808060-id-4065337.html 这篇博文的演示程序。但指定了 .sock 后缀名以后,目的一目了然。
        unix的进程间通信(Inter-Process Communication 简称 IPC)方式有几种:共享内存、套接字、管道、消息队列、信号等
       .sock 就是其中的一种——套接字,而且是 unix domain socket。
       Nginx 父进程与子进程之间的通信方式实质就是 匿名套接字(socketpair),参考:http://ju.outofmemory.cn/entry/125257
        参考资料:

  

  50. 删除 mysql 数据表全部数据 delete table 和 truncate table

 http://www.cnblogs.com/herbert/archive/2010/07/06/1772135.html

  51. wget HTTP response data 回显在控制台

wget 'www.baidu.com' -O -

   52. PHP OO:父类的构造函数不会被自动调用,需要收到执行

parent::__construct();

   不然会报出下面的 PHP Fatal error:  Call to a member function foo() on a non-object in /home/map/odp_wmaudit/app/wmaudit/models/service/....php on line 33。

  53.既然 php zvalue 是 hashtable 那么 foreach 是如何实现的?hash 存取又是如何实现的?

  同理,可以引申出另外一个问题:Hash思想确实很好用,可以帮我们解决元素判重问题,但缺点是 hash 之后元素的排布是无序的,有没有一种数据结构既可以 hash、又可以保持元素原来的顺序?

  54. 为什么有些应用场景中,本机的相对IP (127.0.0.1) 和绝对IP(hostname -i) 不能透明地使用? 比如在 NMQ 中,使用相对 IP 时,pusher 会报错,但是改成 相对IP 就解决了。

  55. SVN merge 以后,报错:local add, incoming add upon merge

  解决方法:svn resolve --accept working -R .  

  56. output specific line with sed.

  This is output the 202947th line to the standard output

sed -n '202947p' train.en

   

  57. GDB debug C program "core dump" error

gcc word2vec
run -train text8 -output vectors.bin -cbow 1 -size 200 -window 8 -negative 25 -hs 0 -sample 1e-4 -threads 2 -binary 1 -iter 15
bt

  使用 bt 命令,可以查看程序调用堆栈,从而找出程序在哪一行出错。

  

  58. sed 删除文件的第一行

sed -i '1d' <file name>

  59. 持续观察 GPU 状态

watch -n -1 nvidia-smi

   

  已解决:

  2. CentOS 7 合上上盖时,机器不休眠。

  4. Nginx 像 Apache 一样列出文件

  5. iptables 添加规则 开放 80 端口

  15. Implemeting the simple sorting of bucket

原文地址:https://www.cnblogs.com/fengyubo/p/5018674.html