C++杂记/读书 2011/12/19

15 篇文章 0 订阅
14 篇文章 0 订阅


## 《Linux C编程》华清远见


1. 文件操作

* sync(), fsync()

sync()只是将所有修改过的block的buffer排入write queue,并不实际执行I/O操作;             // Q:who/when执行?

系统进程update会每隔一定时间间隔(30秒)调用一次sync(),以确保buffer定期refresh。


## Linux C/C++杂记

1. core dump


#ulimit -c unlimited


[root@frank core-dump]# cat coredump.c
#include <stdio.h>

void fatal_error() {
        int i;
        for(i=0;i<10;i++) {
                printf("i=%d\n", i);
        }
        printf(1/0);
}

int main() {
        fatal_error();
}

[root@frank core-dump]# gcc -g coredump.c
coredump.c: 在函数 ‘fatal_error’ 中:
coredump.c:8: 警告:被零除
coredump.c:8: 警告:传递参数 1 (属于 ‘printf’)时将整数赋给指针,未作类型转换
[root@frank core-dump]#

[root@frank core-dump]# gdb a.out core.1412
GNU gdb Red Hat Linux (6.5-25.el5rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/i686/nosegneg/libthread_db.so.1".


warning: Can't read pathname for load map: 输入/输出错误.
Reading symbols from /lib/i686/nosegneg/libc.so.6...done.
Loaded symbols for /lib/i686/nosegneg/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
Core was generated by `./a.out'.
Program terminated with signal 8, Arithmetic exception.
#0  0x080483c1 in fatal_error () at coredump.c:8
8               printf(1/0);
(gdb) where
#0  0x080483c1 in fatal_error () at coredump.c:8
#1  0x080483e3 in main () at coredump.c:12
(gdb) list
3       void fatal_error() {
4               int i;
5               for(i=0;i<10;i++) {
6                       printf("i=%d\n", i);
7               }
8               printf(1/0);
9       }
10
11      int main() {
12              fatal_error();
(gdb) print i
$1 = 10
(gdb)


2. mysql安装


参考URL:http://wanglq.blog.51cto.com/783560/192205


* 下载源代码,解压

* 用户与组

  groupadd mysql
  adduser -g mysql mysql  ???

* 配置compile选项

./configure --prefix=/usr/local/mysql

* build

# make


* install

# make install


* 拷贝config文件到/etc                                            Q:此步遗忘

cp  support-files/my-medium.cnf /etc/my.cnf


* 初始化DB

#cd /usr/local/mysql


[root@frank mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/opt/mydata
Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server          Q:what's this ?
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h frank.zou password 'new-password'
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com


* 文件权限

[root@frank mysql]# chown -R mysql .
[root@frank mysql]# chgrp -R mysql .              Q:for what ?


[root@frank mysql-5.0.22]# pwd
/root/software-repository/mysql-5.0.22

[root@frank mysql-5.0.22]# cp  support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖“/etc/my.cnf”? n                                 // 发现已经有了,估计是安装rpm包的时候放进去的,不知道内容是否完全一样。
[root@frank mysql-5.0.22]#



* start mysql server

[root@frank mysql]#  /usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/opt/mydata &
[1] 1512
[root@frank mysql]# Starting mysqld daemon with databases from /opt/mydata


[root@frank ~]# ps -ef | grep mysql
root      1512  1094  0 23:45 pts/3    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/opt/mydata
mysql     1543  1512  0 23:45 pts/3    00:00:01 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/opt/mydata --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock

root      1595  1557  0 23:48 pts/4    00:00:00 grep mysql


* 连接并使用

#mysql


[root@frank ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
17 rows in set (0.01 sec)


OK!  ( time used, around 45 mins )



* 其它东东

10.设置环境变量
  export PATH=$PATH:/usr/local/mysql/bin
12.启动脚本
  在系统启动时自动启动MySQL数据库服务
  在/etc/rc.local文件内添加下面的行
  /usr/local/mysql/bin/mysqld_saft --user=mysql --datadir=/opt/mydata &
13.MySQL的启动和停止
  如果不用第12步的方法,还可以用下面的方法
  cp support-files/mysql.server /etc/init.d
  cd/etc/init.d ; chmod a+x mysql.server
  修改mysql.server  vim mysql.server
  basedir=/usr/local/mysql
  datadir=/opt/mydata  修改这两行即可
  chkconfig --add mysql.server  把mysql.server添加到chkconfig中
  现在就可以用service mysql.server来启动服务
  也可以用chkconfig来定制开机是否自动启动mysql服务了。。。。


export PATH=$PATH:/usr/local/mysql/bin


##  重读老blog ##

* 关于share lib的老blog

读书时间 2011-05-23 Linux/C/++


* 孤儿进程

读书时间 05/25/2011 Linux C/C++ 孤儿进程


* 关于进程、kill等等深度知识的blog

读书时间 05/28/2011 Linux编程技术详解



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值