工做中遇到的問題總結

  1. HTTP協議中,報文頭部 Content-Length 指的是 \r\n空行以後內容的長度。好比下面的報文:php

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") 的返回值。html

 

  3. telent 命令python

------------------------------------------------------------------------------------mysql

  telent www.shouxiner.com 80linux

  Trying 198.168.11.254 ...nginx

  Connected to localhost.面試

  Escape character is .redis

  GET / index.html HTTP/1.1算法

  Host : www.shouxiner.comsql

 

  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=/^[ \t]*[(private|public|static)( \t)]*function[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f, function, functions/
--regex-php=/^[ \t]*[(private|public|static)]+[ \t]+\$([A-Za-z0-9_]+)[ \t]*/\1/p, property, properties/
--regex-php=/^[ \t]*(const)[ \t]+([A-Za-z0-9_]+)[ \t]*/\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>

 

   

  已解決:

  2. CentOS 7 合上上蓋時,機器不休眠。

  4. Nginx 像 Apache 同樣列出文件

  5. iptables 添加規則 開放 80 端口

  15. Implemeting the simple sorting of bucket

相關文章
相關標籤/搜索