??xml version="1.0" encoding="utf-8" standalone="yes"?>精品久久8x国产免费观看,欧美一区二区三区久久综,狠狠色丁香久久综合婷婷http://www.shnenglu.com/bujiwu/category/9219.htmlzh-cnThu, 29 Apr 2010 16:39:51 GMTThu, 29 Apr 2010 16:39:51 GMT60[转蝲]top命o详解http://www.shnenglu.com/bujiwu/archive/2010/04/27/top.htmlbujiwubujiwuTue, 27 Apr 2010 05:26:00 GMThttp://www.shnenglu.com/bujiwu/archive/2010/04/27/top.htmlhttp://www.shnenglu.com/bujiwu/comments/113700.htmlhttp://www.shnenglu.com/bujiwu/archive/2010/04/27/top.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/113700.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/113700.htmlhttp://blog.chinaunix.net/u/12973/showart_637900.html


top命o是Linux下常用的性能分析工具Q能够实时显C系l中各个q程的资源占用状况,cM于Windows的Q务管理器。下面详l介l它的用方法?

top - 01:06:48 up  1:22,  1 user,  load average: 0.06, 0.60, 0.48
Tasks:  29 total,   1 running,  28 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3% us,  1.0% sy,  0.0% ni, 98.7% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    191272k total,   173656k used,    17616k free,    22052k buffers
Swap:   192772k total,        0k used,   192772k free,   123988k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  1379 root      16   0  7976 2456 1980 S  0.7  1.3   0:11.03 sshd
14704 root      16   0  2128  980  796 R  0.7  0.5   0:02.72 top
     1 root      16   0  1992  632  544 S  0.0  0.3   0:00.90 init
     2 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

l计信息?/h4>

前五行是pȝ整体的统计信息。第一行是d队列信息Q同 uptime 命o的执行结果。其内容如下Q?/p>

01:06:48 当前旉
up 1:22 pȝq行旉Q格式ؓ??/td>
1 user 当前d用户?/td>
load average: 0.06, 0.60, 0.48 pȝ负蝲Q即d队列的^均长度?br> 三个数值分别ؓ 1分钟?分钟?5分钟前到现在的^均倹{?/td>

W二、三行ؓq程和CPU的信息。当有多个CPUӞq些内容可能会超q两行。内容如下:

Tasks: 29 total q程L
1 running 正在q行的进E数
28 sleeping 睡眠的进E数
0 stopped 停止的进E数
0 zombie 僵尸q程?/td>
Cpu(s): 0.3% us 用户I间占用CPU癑ֈ?/td>
1.0% sy 内核I间占用CPU癑ֈ?/td>
0.0% ni 用户q程I间内改变过优先U的q程占用CPU癑ֈ?/td>
98.7% id I闲CPU癑ֈ?/td>
0.0% wa {待输入输出的CPU旉癑ֈ?/td>
0.0% hi  
0.0% si  

最后两行ؓ内存信息。内容如下:

Mem: 191272k total 物理内存总量
173656k used 使用的物理内存总量
17616k free I闲内存总量
22052k buffers 用作内核~存的内存量
Swap: 192772k total 交换区总量
0k used 使用的交换区总量
192772k free I闲交换区总量
123988k cached ~冲的交换区总量?br> 内存中的内容被换出到交换区,而后又被换入到内存,但用过的交换区未被覆盖,
该数值即?strong>内容已存在于内存?/strong>的交换区的大?br> 相应的内存再ơ被换出时可不必再对交换区写入?/td>

q程信息?/h4>

l计信息区域的下ҎCZ各个q程的详l信息。首先来认识一下各列的含义?/p>

序号 列名 含义
a PID q程id
b PPID 父进Eid
c RUSER Real user name
d UID q程所有者的用户id
e USER q程所有者的用户?/td>
f GROUP q程所有者的l名
g TTY 启动q程的终端名。不是从l端启动的进E则昄??
h PR 优先U?/td>
i NI nice倹{负DC高优先U,正DCZ优先U?/td>
j P 最后用的CPUQ仅在多CPU环境下有意义
k %CPU 上次更新到现在的CPU旉占用癑ֈ?/td>
l TIME q程使用的CPU旉总计Q单位秒
m TIME+ q程使用的CPU旉总计Q单?/100U?/td>
n %MEM q程使用?strong>物理内存癑ֈ?/td>
o VIRT q程使用的虚拟内存总量Q单位kb。VIRT=SWAP+RES
p SWAP q程使用的虚拟内存中Q被换出的大,单位kb?/td>
q RES q程使用的、未被换出的物理内存大小Q单位kb。RES=CODE+DATA
r CODE 可执行代码占用的物理内存大小Q单位kb
s DATA 可执行代码以外的部分(数据D??占用?strong>物理? 存大,单位kb
t SHR ׃n内存大小Q单位kb
u nFLT 面错误ơ数
v nDRT 最后一ơ写入到现在Q被修改q的面数?/td>
w S q程状态?br> D=不可中断的睡眠状?br> R=q行
S=睡眠
T=跟踪/停止
Z=僵尸q程
x COMMAND 命o?命o?/td>
y WCHAN 若该q程在睡眠,则显C睡眠中的系l函数名
z Flags d标志Q参?sched.h

默认情况下仅昄比较重要?PID、USER、PR、NI、VIRT、RES、SHR、S?CPU?MEM、TIME+、COMMAND 列。可以通过下面的快捷键来更ҎC内宏V?/p>

更改昄内容

通过 f 键可以选择昄的内宏V按 f 键之后会昄列的列表Q按 a-z 卛_昄或隐藏对应的列,最后按回R键确定?/p>

?o 键可以改变列的显C顺序。按写?a-z 可以相应的列向右移动,而大写的 A-Z 可以相应的列向左移动。最后按回R键确定?/p>

按大写的 F ?O 键,然后?a-z 可以进E按照相应的列进行排序。而大写的 R 键可以将当前的排序倒{?/p>

命o使用

1Q?工具Q命令)名称
top
2Q工P命oQ作?br> 昄pȝ当前的进E和其他状况Q? top是一个动态显CE?卛_以通过用户按键来不断刷新当前状?如果在前台执行该命o,它将独占前台,直到用户l止该程序ؓ? 比较准确的说,top命o提供了实时的对系l处理器的状态监?它将昄pȝ中CPU最“敏感”的Q务列?该命令可以按CPU使用.内存使用和执行时? 对Q务进行排序;而且该命令的很多Ҏ都可以通过交互式命令或者在个h定制文g中进行设?
3Q环境设|?br> 在Linux下用?br> 4Q用方?br> 4Q?使用格式
top [-] [d] [p] [q] [c] [C] [S] [s]  [n]
4Q?参数说明
 d 指定每两ơ屏q信息刷C间的旉间隔。当然用户可以用s交互命o来改变之?br>  p 通过指定监控q程ID来仅仅监控某个进E的状态?br>  q该选项top没有M延迟的进行刷新。如果调用程序有用户权限Q那么top以 可能高的优先q行?br>  S 指定累计模式
 s 使top命o在安全模式中q行。这去除交互命令所带来的潜在危险?br>  i  使top不显CZQ何闲|或者僵死进E?br>  c  昄整个命o行而不只是昄命o?br> 4.3其他
下面介绍在top命o执行q程中可以用的一些交互命令。从使用角度来看Q熟l的掌握q些命o比掌握选项q重要一些。这些命令都是单字母的,如果在命 令行选项中用了s选项Q则可能其中一些命令会被屏蔽掉?br> Ctrl+L 擦除q且重写屏幕?br> h或? 昄帮助画面Q给Z些简短的命oȝ说明?br> k l止一个进E。系l将提示用户输入需要终止的q程PIDQ以及需要发送给该进E什么样的信受一般的l止q程可以使用15信号Q如果不能正常结束那׃? 信号9强制l束该进E。默认值是信号15。在安全模式中此命o被屏蔽?br> i 忽略闲置和僵死进E。这是一个开兛_命o?br> q 退出程序?br> r 重新安排一个进E的优先U别。系l提C用戯入需要改变的q程PID以及需要设|的 q程优先U倹{输入一个正值将使优先降低Q反之则可以使该q程拥有更高的优先权。默认值是10?br> S 切换到篏计模式?br> s 改变两次h之间的gq时间。系l将提示用户输入新的旉Q单位ؓs。如果有数Q? 换成m s。输?值则pȝ不断刷斎ͼ默认值是5 s。需要注意的是如果设|太的旉Q很可能会引起不断刷斎ͼ从而根本来不及看清昄的情况,而且pȝ负蝲也会大大增加?br> f或者F 从当前显CZd或者删除项目?br> o或者O 改变昄目的顺序?br> l 切换昄q_负蝲和启动时间信息?br> m 切换昄内存信息?br> t 切换昄q程和CPU状态信息?br> c 切换昄命o名称和完整命令行?br>  M Ҏȝ内存大小q行排序?br> P ҎCPU使用癑ֈ比大进行排序?br> T Ҏ旉/累计旉q行排序?br>     W 当前设|写入~/.toprc文g中。这是写top配置文g的推荐方法?/span>





bujiwu 2010-04-27 13:26 发表评论
]]>
Unix Network Programming - Vol2 MW记(Chapter 9. Record Locking)http://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.htmlbujiwubujiwuFri, 18 Dec 2009 07:57:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.htmlhttp://www.shnenglu.com/bujiwu/comments/103474.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/12/18/103474.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/103474.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/103474.html
#include <sys/types.h>
#include 
<errno.h>
#include 
<fcntl.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<unistd.h>

#define FILE_PATH   "LockFile.txt"
#define MAXLINE     4096    /* max text line length */
#define FILE_MODE   (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

int LockSet(int fd, int Type)
{
    
struct flock lock;

    
lock.l_type = Type;        /* F_RDLCK, F_WRLCK, F_UNLCK */
    
lock.l_start = 0;          /* byte offset, relative to l_whence */
    
lock.l_whence = SEEK_END;  /* SEEK_SET, SEEK_CUR, SEEK_END */
    
lock.l_len = 0;            /* #bytes (0 means to EOF) */

    
return fcntl( fd, F_SETLK, &lock);
}

int main(int argc, char **argv)
{
    
char line[MAXLINE] = {0};

    
int fd = open(FILE_PATH, O_RDWR | O_CREAT| O_APPEND , FILE_MODE);

    
if ( LockSet(fd, F_WRLCK) < 0 )
    {
        
if (errno == EACCES || errno == EAGAIN)
        {
            printf(
"This program has running!\n");
            close(fd);
        }
        
else
        {
            printf(
"call fcntl function error.%s\n", strerror(errno) );
        }

        exit(
1);
    }

    printf(
"lock file [%s] successful\n", FILE_PATH);

    snprintf(line, 
sizeof(line), "%ld\n", (long) getpid());

    lseek(fd, 
0, SEEK_END);
    write(fd, line, strlen(line));

    getchar();

    
if ( LockSet(fd, F_UNLCK) < 0 )
    {
        printf(
"call fcntl function error.%s\n", strerror(errno) );
    }

    close(fd);

    
return 0;
}
http://www.shnenglu.com/Files/bujiwu/RecordLocking.rar



bujiwu 2009-12-18 15:57 发表评论
]]>
semaphore信号学习W记http://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.htmlbujiwubujiwuTue, 17 Nov 2009 05:28:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.htmlhttp://www.shnenglu.com/bujiwu/comments/101190.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/17/101190.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101190.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101190.htmlsem_init()
sem_destroy()
sem_post()
sem_wait()

//g++ -o semaphore semaphore.cpp  -lpthread
#include <semaphore.h>
#include 
<errno.h>
#include 
<unistd.h>
#include 
<pthread.h>
#include 
<stdlib.h>
#include 
<stdio.h>
#include 
<string.h>
#include 
"ThreadMutex.h"

#define MAXSIZE 10

sem_t g_sem_max;
sem_t g_sem_zero;

CThreadMutex g_mutex;

int g_count = 0;

int sem_wait_i(sem_t* psem)
{
    
int rv = 0;
   
    
while ( 0 != ( rv = sem_wait(psem) ) )
    {
        
if ( errno == EINTR )
        {
            
continue;
        }
        
else
        {
            printf(
"sem_wait %s\n", strerror(errno) );
            
break;
        }
    }

    
return rv;
}

void* producer_thread(void* Parameter)
{
    
whiletrue )
    {
        sleep(
2);

        
if( sem_wait_i(&g_sem_max) != 0 )
        {
            
break;
        }

        g_mutex.Lock();

        g_count
++;

        printf(
"Producer=%d\n", g_count);

        sem_post(
&g_sem_zero);

        g_mutex.UnLock();
    }

    
return NULL;
}

void* consumer_thread(void* Parameter)
{
    
whiletrue )
    {
        sleep(
3);

        
if( sem_wait_i(&g_sem_zero) != 0 )
        {
            
break;
        }

        g_mutex.Lock();

        g_count
--;

        printf(
"Consumer=%d\n", g_count);

        sem_post(
&g_sem_max);

        g_mutex.UnLock();
    }

    
return NULL;
}

int main(int argc, char* argv[])
{
    
if ( sem_init(&g_sem_zero, 00!= 0 )
    {
        printf(
"sem_init %s\n", strerror(errno) );

        
return -1;
    }

    
if ( sem_init(&g_sem_max, 0, MAXSIZE) != 0 )
    {
        printf(
"sem_init %s\n", strerror(errno) );

        
return -1;
    }

    pthread_t pro_thread;
    pthread_t sum_thread;

    
if ( pthread_create( &sum_thread, NULL, consumer_thread, NULL) != 0 )
    {
        printf(
"pthread_create%s\n", strerror(errno) );

        
return -1;
    }

    
if ( pthread_create( &pro_thread, NULL, producer_thread, NULL) != 0 )
    {
        printf(
"pthread_create%s\n", strerror(errno) );

        
return -1;
    }
    
    
if ( pthread_join(pro_thread, NULL) != 0 )
    {
        printf(
"pthread_join %s\n", strerror(errno) );

        
return -1;
    }

    
if ( pthread_join(sum_thread, NULL) != 0 )
    {
        printf(
"pthread_join %s\n", strerror(errno) );

        
return -1;
    }

    sem_destroy(
&g_sem_zero);
    sem_destroy(
&g_sem_max);

    
return 0;
}
http://www.shnenglu.com/Files/bujiwu/semaphore.rar



bujiwu 2009-11-17 13:28 发表评论
]]>
setitimer函数使用W记http://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.htmlbujiwubujiwuMon, 16 Nov 2009 05:50:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.htmlhttp://www.shnenglu.com/bujiwu/comments/101061.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/16/101061.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/101061.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/101061.html函数原型 int setitimer(int which, const struct itimerval *value,
                     struct itimerval *ovalue);

DESCRIPTION
       The  system  provides each process with three interval timers, each decrementing in a distinct time domain.  When any timer expires, a
       signal is sent to the process, and the timer (potentially) restarts.

       ITIMER_REAL    decrements in real time, and delivers SIGALRM upon expiration.

       ITIMER_VIRTUAL decrements only when the process is executing, and delivers SIGVTALRM upon expiration.

       ITIMER_PROF    decrements both when the process executes and when the system is executing on behalf  of  the  process.   Coupled  with
                      ITIMER_VIRTUAL, this timer is usually used to profile the time spent by the application in user and kernel space.  SIG-
                      PROF is delivered upon expiration.

       Timer values are defined by the following structures:

            struct itimerval {
                struct timeval it_interval; /* next value */
                struct timeval it_value;    /* current value */
            };
            struct timeval {
                long tv_sec;                /* seconds */
                long tv_usec;               /* microseconds */
            };

#include <stdio.h>
#include 
<unistd.h>
#include 
<signal.h>
#include 
<string.h>
#include 
<sys/time.h>
#include 
<errno.h>

void PrintMsg(int Num)
{
    printf(
"%s\n""Hello World");

    
return;
}

int main(int argc, char* argv[])
{
    signal(SIGALRM, PrintMsg);

    
struct itimerval tick;
    tick.it_value.tv_sec 
= 10;  //十秒钟后启动定时器
    tick.it_value.tv_usec = 0;
    tick.it_interval.tv_sec  
=1//定时器启动后Q每?U将执行相应的函?/span>
    tick.it_interval.tv_usec = 0;

    
//setitimer触发SIGALRM信号
    int ret = setitimer(ITIMER_REAL, &tick, NULL);

    
if ( ret != 0)
    {
        printf(
"Set timer error. %s \n", strerror(errno) );

        
return -1;
    }

    printf(
"Wait!\n");

    getchar();

    
return 0;
}



bujiwu 2009-11-16 13:50 发表评论
]]>
pthread_mutex_t装http://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.htmlbujiwubujiwuSun, 08 Nov 2009 12:57:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.htmlhttp://www.shnenglu.com/bujiwu/comments/100413.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/08/pthread_mutex.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100413.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100413.html
//Mutex.cpp
#include 
<pthread.h>
#include 
<iostream>
using namespace std;

class ThreadMutex
{
public:
    ThreadMutex()
    {
        pthread_mutex_init(
&mtx, NULL);
    }
    
    
~ThreadMutex()
    {
        pthread_mutex_destroy( 
&mtx );
    }
    
    inline 
void Lock()
    {
        pthread_mutex_lock( 
&mtx );
    }
    
    inline 
void UnLock()
    {
        pthread_mutex_unlock( 
&mtx );
    }
    
private:
    pthread_mutex_t mtx;
};                                                            

//以下为测试用?br>ThreadMutex g_Mutex;

void *PrintMsg(void *lpPara)
{
    
char *msg = (char *)lpPara;

    g_Mutex.Lock();

    
for(int i=0; i< 5; i++ )
    {
        cout 
<< msg << endl;
        sleep( 
1 );
    }

    g_Mutex.UnLock();

    
return NULL;
}

int main()
{
    pthread_t t1,t2;

    
//创徏两个工作U程Q第1个线E打?0?Q第2个线E打?0??/span>
    pthread_create( &t1, NULL, &PrintMsg, (void *)"First print thread" );       
    pthread_create( 
&t2, NULL, &PrintMsg, (void *)"Second print thread" );        

    
//{待U程l束                                             
    pthread_join( t1, NULL);                               
    pthread_join( t2, NULL);                               

    
return 0;                                             
}    

通过g++ -o Mutex Mutex.cpp -lpthread~译?br>

bujiwu 2009-11-08 20:57 发表评论
]]>
q程间通讯--System V ׃n内存http://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.htmlbujiwubujiwuSun, 08 Nov 2009 01:39:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.htmlhttp://www.shnenglu.com/bujiwu/comments/100390.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/08/100390.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100390.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100390.html
#include <sys/ipc.h>
#include 
<sys/shm.h>
#include 
<unistd.h>
#include 
<errno.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<errno.h>
#include 
<sys/types.h>

using namespace std;


int main(int argc, char* argv[])
{
    key_t key 
= ftok("/etc/passwd"'a');
    
if-1 == key )
    {
        fprintf(stderr, 
"Creat Key Error:%s\n", strerror(errno));
        
return -1;
    }
    
    
/*
     if your IPC are used by processes related bya fork() 
    (parent-children-grandchildren) use IPC_PRIVATE as the key
    
*/
    
int shm_id=shmget( key, 1024, IPC_CREAT |0660);

    
if( shm_id == -1 )
    {
        
if ( shmctl(shm_id, IPC_RMID, NULL) == -1 )
        {
            fprintf(stderr, 
"shmctl remove shmid error:%s\n", strerror(errno ));
            
return -1;
        }

        shm_id
=shmget( key, 1024, IPC_CREAT |0660);
        
if( shm_id == -1 )
        {
            fprintf(stderr, 
"shmget create error:%s\n", strerror(errno) );
            
return -1;
        }
    }

    
char* pMap = (char *)shmat(shm_id, NULL, 0);

    
if( (int)pMap == -1)
    {
        fprintf(stderr, 
"shmat create error:%s\n", strerror(errno) );
        shmctl(shm_id, IPC_RMID, NULL);
        
return -1;
    }

    strcpy( pMap, 
"Bujiwu Swallow");

    getchar();

    shmdt(pMap);
    shmctl(shm_id, IPC_RMID, NULL);

    
return 0;
}

#include <sys/ipc.h>
#include 
<sys/shm.h>
#include 
<unistd.h>
#include 
<errno.h>
#include 
<stdio.h>
#include 
<stdlib.h>
#include 
<string.h>
#include 
<errno.h>
#include 
<sys/types.h>

using namespace std;

int main(int argc, char* argv[])
{
    key_t key 
= ftok("/etc/passwd"'a');
    
if-1 == key )
    {
        fprintf(stderr, 
"Creat Key Error:%s\n", strerror(errno));
        
return -1;
    }
    
    
/*
     if your IPC are used by processes related bya fork() 
    (parent-children-grandchildren) use IPC_PRIVATE as the key
    
*/
    
int shm_id=shmget( key, 1024, IPC_CREAT|0660);
    
    
if( shm_id == -1 )
    {
        
if ( shmctl(shm_id, IPC_RMID, NULL) == -1 )
        {
            fprintf(stderr, 
"shmctl remove shmid error:%s\n", strerror(errno ));
            
return -1;
        }

        shm_id
=shmget( key, 1024, IPC_CREAT |0660);
        
if( shm_id == -1 )
        {
            fprintf(stderr, 
"shmget create error:%s\n", strerror(errno) );
            
return -1;
        }
    }
    
char* pMap = (char *)shmat(shm_id, NULL, 0);

    
if( (int)pMap == -1)
    {
        fprintf(stderr, 
"shmat create error:%s\n", strerror(errno) );
        shmctl(shm_id, IPC_RMID, NULL);
        
return -1;
    }

    printf(
"Shared  memory::%s\n", pMap);

    shmdt(pMap);
    shmctl(shm_id, IPC_RMID, NULL);

    
return 0;
}

http://www.shnenglu.com/Files/bujiwu/ShareMemory.rar


bujiwu 2009-11-08 09:39 发表评论
]]>
q程间通讯--System V 消息队列http://www.shnenglu.com/bujiwu/archive/2009/11/07/100356.htmlbujiwubujiwuSat, 07 Nov 2009 13:47:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/07/100356.htmlhttp://www.shnenglu.com/bujiwu/comments/100356.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/07/100356.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100356.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100356.html阅读全文

bujiwu 2009-11-07 21:47 发表评论
]]>
转蝲:什么是Core Dumphttp://www.shnenglu.com/bujiwu/archive/2009/11/05/100204.htmlbujiwubujiwuThu, 05 Nov 2009 05:12:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/05/100204.htmlhttp://www.shnenglu.com/bujiwu/comments/100204.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/05/100204.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/100204.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/100204.html http://blog.chinaunix.net/u/16292/showart_1844400.html

1、什么是Core Dump?
Core的意思是内存, Dump的意思是扔出? 堆出?
开发和使用UnixE序? 有时E序莫名其妙的down? 却没有Q何的提示(有时候会提示core dumped). q时候可以查看一下有没有形如core.q程L文g生成, q个文g便是操作pȝ把程序down掉时的内存内Ҏ出来生成? 它可以做试程序的参?
core dump又叫核心转储, 当程序运行过E中发生异常, E序异常退出时, 由操作系l把E序当前的内存状况存储在一个core文g? 叫core dump.

2、如何用core文g?
gdb -c core文g路径 [应用E序的\径]
q去后输入where回R, 可以显C程序在哪一行当掉的, 在哪个函C.

3、ؓ什么没有core文g生成?
有时候程序down? 但是core文g却没有生? core文g的生成跟你当前系l的环境讄有关p? 可以用下面的语句讄一? 然后再运行程序便成生成core文g.
ulimit -c unlimited
core文g生成的位|一般于q行E序的\径相? 文g名一般ؓcore.q程?br>
4、用gdb查看core文g:
下面我们可以在发生运行时信号引v的错误时发生core dump?
发生core dump之后, 用gdbq行查看core文g的内? 以定位文件中引发core dump的行.
gdb [exec file] [core file]
?
gdb ./test test.core
在进入gdb? 用bt命o查看backtrace以检查发生程序运行到哪里, 来定位core dump的文?>?


bujiwu 2009-11-05 13:12 发表评论
]]>
创徏守护q程函数http://www.shnenglu.com/bujiwu/archive/2009/11/01/99952.htmlbujiwubujiwuSun, 01 Nov 2009 14:15:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/11/01/99952.htmlhttp://www.shnenglu.com/bujiwu/comments/99952.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/11/01/99952.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/99952.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/99952.htmlvoid DaemonInit(void
{
    pid_t pid;
    pid_t sid;

    
// fork to leave parent
    pid = fork ();
    
if (pid < 0
    {
        std::cout 
<< "failed to fork!" << std::endl;

        exit (EXIT_FAILURE);
    } 
    
else if (pid > 0
    {
        
//parent process go to exit
        exit (EXIT_SUCCESS);
    }

    
//child process 
    sid = setsid ();
    
if (sid < 0
    {
        std::cout 
<< "Failed to set session id." << std::endl;

        exit (EXIT_FAILURE);
    }
    
    
return;
}



bujiwu 2009-11-01 22:15 发表评论
]]>
Linux与Windows中mapceraseҎ的差?/title><link>http://www.shnenglu.com/bujiwu/archive/2009/11/01/map.html</link><dc:creator>bujiwu</dc:creator><author>bujiwu</author><pubDate>Sun, 01 Nov 2009 02:40:00 GMT</pubDate><guid>http://www.shnenglu.com/bujiwu/archive/2009/11/01/map.html</guid><wfw:comment>http://www.shnenglu.com/bujiwu/comments/99928.html</wfw:comment><comments>http://www.shnenglu.com/bujiwu/archive/2009/11/01/map.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.shnenglu.com/bujiwu/comments/commentRss/99928.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bujiwu/services/trackbacks/99928.html</trackback:ping><description><![CDATA[<div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: #008080;"> 1</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">iostream</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 2</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #000000;">map</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 3</span> <span style="color: #000000;">#include </span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">></span><span style="color: #000000;"><br></span><span style="color: #008080;"> 4</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 5</span> <span style="color: #000000;"></span><span style="color: #0000ff;">using</span><span style="color: #000000;"> </span><span style="color: #0000ff;">namespace</span><span style="color: #000000;">  std;<br></span><span style="color: #008080;"> 6</span> <span style="color: #000000;"><br></span><span style="color: #008080;"> 7</span> <span style="color: #000000;"></span><span style="color: #0000ff;">int</span><span style="color: #000000;"> main(</span><span style="color: #0000ff;">int</span><span style="color: #000000;"> argc, </span><span style="color: #0000ff;">char</span><span style="color: #000000;">*</span><span style="color: #000000;"> argv[])<br></span><span style="color: #008080;"> 8</span> <span style="color: #000000;">{<br></span><span style="color: #008080;"> 9</span> <span style="color: #000000;">    map</span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">, </span><span style="color: #0000ff;">int</span><span style="color: #000000;">></span><span style="color: #000000;"> MyMap;<br></span><span style="color: #008080;">10</span> <span style="color: #000000;"><br></span><span style="color: #008080;">11</span> <span style="color: #000000;">    MyMap[</span><span style="color: #000000;">"</span><span style="color: #000000;">bujiwu</span><span style="color: #000000;">"</span><span style="color: #000000;">] </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">26</span><span style="color: #000000;">;<br></span><span style="color: #008080;">12</span> <span style="color: #000000;">    MyMap[</span><span style="color: #000000;">"</span><span style="color: #000000;">swallow</span><span style="color: #000000;">"</span><span style="color: #000000;">] </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">25</span><span style="color: #000000;">;<br></span><span style="color: #008080;">13</span> <span style="color: #000000;"><br></span><span style="color: #008080;">14</span> <span style="color: #000000;">    std::cout </span><span style="color: #000000;"><<</span><span style="color: #000000;">"</span><span style="color: #000000;">Before delete element:</span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;"><<</span><span style="color: #000000;"> std::endl;<br></span><span style="color: #008080;">15</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;">( map</span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">, </span><span style="color: #0000ff;">int</span><span style="color: #000000;">></span><span style="color: #000000;">::iterator Itor </span><span style="color: #000000;">=</span><span style="color: #000000;"> MyMap.begin();<br></span><span style="color: #008080;">16</span> <span style="color: #000000;">            Itor </span><span style="color: #000000;">!=</span><span style="color: #000000;"> MyMap.end(); Itor</span><span style="color: #000000;">++</span><span style="color: #000000;"> )<br></span><span style="color: #008080;">17</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">18</span> <span style="color: #000000;">        std::cout </span><span style="color: #000000;"><<</span><span style="color: #000000;"> Itor</span><span style="color: #000000;">-></span><span style="color: #000000;">first </span><span style="color: #000000;"><<</span><span style="color: #000000;"> </span><span style="color: #000000;">"</span><span style="color: #000000;">   </span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;"><<</span><span style="color: #000000;"> Itor</span><span style="color: #000000;">-></span><span style="color: #000000;">second </span><span style="color: #000000;"><<</span><span style="color: #000000;"> std::endl;<br></span><span style="color: #008080;">19</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">20</span> <span style="color: #000000;"><br></span><span style="color: #008080;">21</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;">( map</span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">, </span><span style="color: #0000ff;">int</span><span style="color: #000000;">></span><span style="color: #000000;">::iterator Itor </span><span style="color: #000000;">=</span><span style="color: #000000;"> MyMap.begin();<br></span><span style="color: #008080;">22</span> <span style="color: #000000;">            Itor </span><span style="color: #000000;">!=</span><span style="color: #000000;"> MyMap.end(); )<br></span><span style="color: #008080;">23</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">24</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> ( Itor</span><span style="color: #000000;">-></span><span style="color: #000000;">first </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #000000;">"</span><span style="color: #000000;">bujiwu</span><span style="color: #000000;">"</span><span style="color: #000000;"> )<br></span><span style="color: #008080;">25</span> <span style="color: #000000;">        {<br></span><span style="color: #008080;">26</span> <span style="color: #000000;">            MyMap.erase(Itor</span><span style="color: #000000;">++</span><span style="color: #000000;">); <span style="color: red;">//在windows下也可以Itor = MyMap.erase(Itor),但是在linux下不行?/span><br></span><span style="color: #008080;">27</span> <span style="color: #000000;">        }<br></span><span style="color: #008080;">28</span> <span style="color: #000000;">        </span><span style="color: #0000ff;">else</span><span style="color: #000000;"><br></span><span style="color: #008080;">29</span> <span style="color: #000000;">        {<br></span><span style="color: #008080;">30</span> <span style="color: #000000;">            Itor</span><span style="color: #000000;">++</span><span style="color: #000000;">;<br></span><span style="color: #008080;">31</span> <span style="color: #000000;">        }<br></span><span style="color: #008080;">32</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">33</span> <span style="color: #000000;"><br></span><span style="color: #008080;">34</span> <span style="color: #000000;">    std::cout </span><span style="color: #000000;"><<</span><span style="color: #000000;">"</span><span style="color: #000000;">After delete element:</span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;"><<</span><span style="color: #000000;"> std::endl;<br></span><span style="color: #008080;">35</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">for</span><span style="color: #000000;">( map</span><span style="color: #000000;"><</span><span style="color: #0000ff;">string</span><span style="color: #000000;">, </span><span style="color: #0000ff;">int</span><span style="color: #000000;">></span><span style="color: #000000;">::iterator Itor </span><span style="color: #000000;">=</span><span style="color: #000000;"> MyMap.begin();<br></span><span style="color: #008080;">36</span> <span style="color: #000000;">            Itor </span><span style="color: #000000;">!=</span><span style="color: #000000;"> MyMap.end(); Itor</span><span style="color: #000000;">++</span><span style="color: #000000;"> )<br></span><span style="color: #008080;">37</span> <span style="color: #000000;">    {<br></span><span style="color: #008080;">38</span> <span style="color: #000000;">        std::cout </span><span style="color: #000000;"><<</span><span style="color: #000000;"> Itor</span><span style="color: #000000;">-></span><span style="color: #000000;">first </span><span style="color: #000000;"><<</span><span style="color: #000000;"> </span><span style="color: #000000;">"</span><span style="color: #000000;">   </span><span style="color: #000000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;"><<</span><span style="color: #000000;"> Itor</span><span style="color: #000000;">-></span><span style="color: #000000;">second </span><span style="color: #000000;"><<</span><span style="color: #000000;"> std::endl;<br></span><span style="color: #008080;">39</span> <span style="color: #000000;">    }<br></span><span style="color: #008080;">40</span> <span style="color: #000000;"><br></span><span style="color: #008080;">41</span> <span style="color: #000000;">    </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">;<br></span><span style="color: #008080;">42</span> <span style="color: #000000;">}<br></span><span style="color: #008080;">43</span> <span style="color: #000000;"></span><span style="color: #000000;"></span><span style="color: #000000;"><br></span><span style="color: #008080;">44</span> <span style="color: #000000;"></span></div> <br>通过试在不在linuxq是Windowsq_?vector,list都有Ҏ<strong>iterator erase(</strong> <strong> iterator </strong>_Where <strong>);</strong> <br>但是在Linux下map中没有方?strong>iterator erase(</strong> <strong> iterator </strong>_Where <strong>);</strong> 所以上qC码在Linuxq_下第26行必d成MyMap.erase(Itor++),而不能写能Itor = MyMap.erase(Itor). 在Windows下二U方法都可以?br><br> <img src ="http://www.shnenglu.com/bujiwu/aggbug/99928.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bujiwu/" target="_blank">bujiwu</a> 2009-11-01 10:40 <a href="http://www.shnenglu.com/bujiwu/archive/2009/11/01/map.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>fork学习W记http://www.shnenglu.com/bujiwu/archive/2009/09/13/96062.htmlbujiwubujiwuSun, 13 Sep 2009 12:25:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/09/13/96062.htmlhttp://www.shnenglu.com/bujiwu/comments/96062.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/09/13/96062.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/96062.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/96062.html 1 #include <unistd.h>
 2 #include <sys/types.h>
 3 #include <stdio.h>
 4 #include <string.h>
 5 #include <errno.h>
 6 
 7 int main(int argc ,char* argv[])
 8 {
 9     pid_t my_pid = getpid();
10     pid_t parent_pid = getppid();
11 
12     printf("ProcessID =%ld  ParentID =%ld\n", my_pid, parent_pid);
13 
14     pid_t child = fork();
15 
16     printf("-------------------------------------\n");
17     printf("Fork Process ID = %ld \n", child );
18 
19     switch( child )
20     {
21         case -1:
22                printf("Create my child process error by fork func, errno=%ld\n", strerror(errno) );
23                break;
24 
25         case 0:
26               printf("This is child process! Process ID = %ld\n", getpid() );
27               break;
28 
29         default:
30               printf("This is not child process! Process ID= %ld Child Process ID=%ld\n", getpid(), child);
31                
32     }
33     
34     printf("who am I? Process ID=%ld  Parent Process ID= %ld\n", getpid(), getppid());
35 
36     return 0;
37 }
38 
q行l果[swallow@localhost syspr]$ ./process
ProcessID =1182  ParentID =1090
-------------------------------------
Fork Process ID = 0
This is child process! Process ID = 1183
who am I? Process ID=1183  Parent Process ID= 1182
-------------------------------------
Fork Process ID = 1183
This is not child process! Process ID= 1182 Child Process ID=1183
who am I? Process ID=1182  Parent Process ID= 1090
[swallow@localhost syspr]$

http://www.shnenglu.com/Files/bujiwu/fork.rar



bujiwu 2009-09-13 20:25 发表评论
]]>
Linuxd环境变量与GCC~译器添加INCLUDE与LIB环境变量http://www.shnenglu.com/bujiwu/archive/2009/01/25/72575.htmlbujiwubujiwuSun, 25 Jan 2009 10:20:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/01/25/72575.htmlhttp://www.shnenglu.com/bujiwu/comments/72575.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/01/25/72575.html#Feedback2http://www.shnenglu.com/bujiwu/comments/commentRss/72575.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/72575.html.bashrc?bash_profile里增加下面的内容Q?br>(注意Q等号前面不要加I格,否则可能出现 command not found)

#在PATH中找到可执行文gE序的\径?br>export PATH =$PATH:$HOME/bin

#gcc扑ֈ头文件的路径
C_INCLUDE_PATH=/usr/include/libxml2:/MyLib
export C_INCLUDE_PATH

#g++扑ֈ头文件的路径
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/libxml2:/MyLib
export CPLUS_INCLUDE_PATH

#扑ֈ动态链接库的\?br>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/MyLib
export LD_LIBRARY_PATH

#扑ֈ静态库的\?br>LIBRARY_PATH=$LIBRARY_PATH:/MyLib
export LIBRARY_PATH


bujiwu 2009-01-25 18:20 发表评论
]]>
LinuxU程学习W记http://www.shnenglu.com/bujiwu/archive/2009/01/18/72256.htmlbujiwubujiwuSun, 18 Jan 2009 06:00:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/01/18/72256.htmlhttp://www.shnenglu.com/bujiwu/comments/72256.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/01/18/72256.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/72256.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/72256.html 1 #include <stdio.h>       /* standard I/O routines                 */
 2 #include <pthread.h>     /* pthread functions and data structures */
 3 #include <unistd.h>      /* head file for sleep function */
 4 
 5 /* global mutex for our program. assignment initializes it */
 6 pthread_mutex_t a_mutex = PTHREAD_MUTEX_INITIALIZER;
 7 
 8 /* function to be executed by the new thread */
 9 void* do_loop(void* data)
10 {
11     int me = *((int*)data);     /* thread identifying number */
12     int rc; /* contain mutex lock/unlock results */
13     
14     /* lock the mutex, to assure exclusive */
15     rc = pthread_mutex_lock(&a_mutex);
16     
17     for (int i=0; i< 4; i++
18     {
19         printf("'%d' - Got '%d'\n", me, i);
20         sleep(1);
21     }
22 
23     /* unlock mutex */
24     rc = pthread_mutex_unlock(&a_mutex);
25     
26     /* terminate the thread */
27     pthread_exit(NULL);
28 }
29 
30 /* like any CPlusPlus program, program's execution begins in main */
31 /*g++ -o Thread Thread.cpp -lpthread*/
32 int main(int argc, char* argv[])
33 {
34     int        thr_id;         /* thread ID for the newly created thread */
35     pthread_t  p_thread1;       /* thread's structure                     */
36     pthread_t  p_thread2;       /* thread's structure                     */
37     int        a = 1;  /* thread 1 identifying number            */
38     int        b = 2;  /* thread 2 identifying number            */
39 
40     /* create a new thread that will execute 'do_loop()' */
41     thr_id = pthread_create(&p_thread1, NULL, do_loop, (void*)&a);
42     
43     /* create a new thread */
44     thr_id = pthread_create(&p_thread2, NULL, do_loop, (void*)&b);
45     
46     /*wait until sub thread exit*/
47     pthread_join(p_thread1, NULL);
48     pthread_join(p_thread2, NULL);
49 
50     return 0;
51 }
52 
~译Q?nbsp;gcc -o pthread pthread.c  -lpthread




bujiwu 2009-01-18 14:00 发表评论
]]>
Gvim操作汇?/title><link>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71166.html</link><dc:creator>bujiwu</dc:creator><author>bujiwu</author><pubDate>Sun, 04 Jan 2009 13:39:00 GMT</pubDate><guid>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71166.html</guid><wfw:comment>http://www.shnenglu.com/bujiwu/comments/71166.html</wfw:comment><comments>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71166.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bujiwu/comments/commentRss/71166.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bujiwu/services/trackbacks/71166.html</trackback:ping><description><![CDATA[1、Vim中替换操?br>   s/old/new/g   #替换当前行old为new<br>   6,7s/old/new/g  #替换W六行到W七行中的old为new<br>   %s/old/new/g    #替换全部的old为new<br><br>2、查扑֭W串<br>   :/Count    #正向查找Count  按n昄下一?br>   :%Count    #逆向查找Count <br>   在当前字W串上按*,正向查找当前字符?br>   在当前字W串上按#,反向查找当前字符?br> <br>3、字W串联想<br>   Ctrl+p<br><br>4、重复上一行内?br>   Ctrl+y<br><br>5、蟩?br>   gg  跛_文g首行<br>   G   跛_文g行<br>   123G 跛_W?23?br>   数字0 Ud当前行末?br>   $     Ud当前行首?br>   光标在{、}、[、]{括号上?跛_相应的括号上<br>6、新增一?br>   o   在当前光标下一行新增一?br>   O   在当前光标上一行新增一?br><br>7、显C?隐藏行号<br>   set nu 昄行号<br>   set nonu 隐藏{号<br><br>8、在Gvim中执行外部shell命o<br>   :!外部命oQ如:<br>   :!ls -l<br><br>9、删?复制?br>   dd 删除一?br>   3dd 删除当前光标所在行的以下三?br>   yy  复制一?br>   3yy 复制三行<br>   p _脓<br><br>10、撤消与撤消的撤?br>   u 撤消<br>   Ctrl+R 撤消的撤?br><br><br>.vimrc模板<br><a href="http://www.shnenglu.com/Files/bujiwu/vimrc.rar">http://www.shnenglu.com/Files/bujiwu/vimrc.rar</a><br><br>"============================================<br>syntax on<br>set nu<br><br>set autoindent<br>set cindent<br>set smartindent<br><br>set softtabstop=4<br>set tabstop=4<br>set shiftwidth=4<br>set expandtab<br>set smarttab<br><br>set nobackup<br><br>set cursorline<br><br>set tags="./tags,./../tags,./../../tags"<br>"=================================================<br><br> <br> <img src ="http://www.shnenglu.com/bujiwu/aggbug/71166.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bujiwu/" target="_blank">bujiwu</a> 2009-01-04 21:39 <a href="http://www.shnenglu.com/bujiwu/archive/2009/01/04/71166.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下文件打包与解包http://www.shnenglu.com/bujiwu/archive/2009/01/04/71152.htmlbujiwubujiwuSun, 04 Jan 2009 11:23:00 GMThttp://www.shnenglu.com/bujiwu/archive/2009/01/04/71152.htmlhttp://www.shnenglu.com/bujiwu/comments/71152.htmlhttp://www.shnenglu.com/bujiwu/archive/2009/01/04/71152.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/71152.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/71152.html  tar -cvf Pro.tar /home/lin/Pro   #?home/lin/Pro文g夹下的所有文件打包成Pro.tar

打解?.tar.gz)
  tar -cvzf firefox-3.0.3.tar.gz firefox       #firefox文gҎ包ؓfirefox-3.0.3.tar.gz
  tar -xvzf firefox-3.0.3.tar.gz

打解?.tar.bz2)
  tar -cvjf firefox-3.0.3.tar.bz2  firefox/    #firefox文gҎ包ؓfirefox-3.0.3.tar.bz2
  tar -xvjf firefox-3.0.3.tar.bz2

参数说明Q?br>c   创徏新的档案文g。如果用h备䆾一个目录或是一些文Ӟp选择q个选项?br>x   从档案文件中释放文g?br>v   详细报告tar处理的文件信息。如无此选项Qtar不报告文件信息?br>z   用gzip来压~?解压~文Ӟ加上该选项后可以将档案文gq行压羃Q但q原时也一定要使用该选项q行解压~?
f   使用档案文g或设备,q个选项通常是必选的?br>




bujiwu 2009-01-04 19:23 发表评论
]]>
Linux常用知识攉Q?/title><link>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71149.html</link><dc:creator>bujiwu</dc:creator><author>bujiwu</author><pubDate>Sun, 04 Jan 2009 11:06:00 GMT</pubDate><guid>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71149.html</guid><wfw:comment>http://www.shnenglu.com/bujiwu/comments/71149.html</wfw:comment><comments>http://www.shnenglu.com/bujiwu/archive/2009/01/04/71149.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bujiwu/comments/commentRss/71149.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bujiwu/services/trackbacks/71149.html</trackback:ping><description><![CDATA[1、程序前C后台切换<br>   ctrl+z  进E切换到后台<br>   fg      调到前台<br><br>2、linux扚w查找文g内容<br>   find ./ -name "*.cpp" | xargs grep '要查扄内容'<br>   ?find . -name "*.cpp" | xargs grep 'main'<br><br>   如果需要查扄内容包含ҎW号Q比?{等Qgrep要加参数<br>   find ./ -name "*.cpp" | xargs grep -F '要查扄内容'<br><br>3、删除特定类型的文g<br>   ?后缀?log的文?br>   find . -name "*.log"  -exec rm {} \;<br>   或? find . -name "*.log" | xargs rm<br><br><br>4、文件批量重命名<br>   所?.h后缀名的文g重命名ؓ*.header<br>   rename .h .header *.h<br>   格式Q?rename 替换前的内容 替换后的内容 通配W?br>   <br>5、列出除什么之外的文g<br>   列出不包括swallow字符的文Ӟ ls | grep -v swallow<br>   删除不包括swallow字符的文Ӟ ls | grep -v swallow | xargs rm<br><br>6、将用户增加到sudol?br>   root# vim /etc/sudoers<br>   在这里增加内容:<br>   ## Allow root to run any commands anywhere <br>   root    ALL=(ALL)   ALL<br>   bujiwu  ALL=(ALL)   ALL<br>   <br>7、修?etc/crontab文g增加pȝ定时q行E序功能<br><br>8、make时检到旉错误。您的创建可能是不完?<br>   ׃文g旉与系l时钟不匚w。所以可以用touch更改文g旉来Update.<br>   find . -type f -exec touch {} \; <br><img src ="http://www.shnenglu.com/bujiwu/aggbug/71149.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bujiwu/" target="_blank">bujiwu</a> 2009-01-04 19:06 <a href="http://www.shnenglu.com/bujiwu/archive/2009/01/04/71149.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下Makefile文ghttp://www.shnenglu.com/bujiwu/archive/2008/12/29/70720.htmlbujiwubujiwuMon, 29 Dec 2008 14:40:00 GMThttp://www.shnenglu.com/bujiwu/archive/2008/12/29/70720.htmlhttp://www.shnenglu.com/bujiwu/comments/70720.htmlhttp://www.shnenglu.com/bujiwu/archive/2008/12/29/70720.html#Feedback0http://www.shnenglu.com/bujiwu/comments/commentRss/70720.htmlhttp://www.shnenglu.com/bujiwu/services/trackbacks/70720.html
生成动态库(*.so)Makefile文g#Lib information
CURDIR =$(shell pwd)
LIBNAME :=libmyso.so
OUTDIR :=$(CURDIR)
OUTFILE :=$(OUTDIR)/$(LIBNAME)

SRC =node.cpp
OBJS =$(SRC:.cpp=.o)

#Complier information
CC = g++
INCPATH :=
LIBPATH :=
LIBS :=
COMOPT := -O2

all:$(OBJS)
    $(CC) -fPIC -shared -o $(OUTFILE) $(OBJS)
    
%.o:%.cpp
    $(CC) -c $(COMOPT) $(INCPATH) -o $@ $<

clean:
    rm -rf $(CURDIR)/*.o


生成静态库(*.a)Makefile文g#lib information
CURDIR =$(shell pwd)
LIBNAME :=libmylib.a
OUTDIR :=$(CURDIR)
OUTFILE :=$(OUTDIR)/$(LIBNAME)

SRC = Display.cpp
OBJS =$(SRC:.cpp=.o)

#complier information
CC=g++
INCPATH :=
LIBPATH :=
LIBS :=
COMOPT := -O2

all:$(OBJS)
    ar -r $(OUTFILE) $(OBJS)
    
%.o:%.cpp
    $(CC) -c $(COMOPT) $(INCPATH) -o $@ $<

clean:
    rm -rf $(CURDIR)/*.o


比较通用的Makefile文g#CPP Files Directory
vpath %.cpp ./../   
vpath %.cpp ./../Student

#Head Files Directory    
vpath %.h ./../Student/

#Get Makefile Current Directory
CURDIR =$(shell pwd)

SRC =Main.cpp \
     Student.cpp
     
SRC_OBJ =$(SRC:.cpp=.o)
CCFLAGS =-O2 -g -DUT_4_16
CXX =g++
CPPFLAGS =

#Load Static Library
LIBDIR =-L $(CURDIR)/../StaticLib  -lmylib $(CURDIR)/../DynamicLib/libmyso.so
#Load Library Head Files
INCDIR =-I $(CURDIR)/../StaticLib  -I $(CURDIR)/../DynamicLib

.PHONY :all
all :edit run

.PHONY :edit
edit: $(SRC_OBJ)
$(SRC_OBJ):%.o :%.cpp
    $(CXX) $(INCDIR) -c $(CCFLAGS) $(CPPFLAGS) $< -o $@
   
.PHONY :run
run: $(SRC_OBJ)
    $(CXX) $(INCDIR) $(SRC_OBJ) $(LIBDIR) -o Main
   
.PHONY :clean
clean:
    rm $(SRC_OBJ)

最单的Makefile文g#假设只有一个文件Main.cpp生成Makefile文g
Main:Main.o
    g++ -o $@ $^
%.o:%.cpp %.h
    g++ -c $@ $>

不需要手工添加各个文件的依赖关系Q用vpath自动搜烦文gQ?br> 试工程Q?br> http://www.shnenglu.com/Files/bujiwu/Linux.rar




bujiwu 2008-12-29 22:40 发表评论
]]>
þþƷ99þ޶ | 97þۺɫۺɫhd| þĻ| þþþþŮ| þҹ³Ƭ| ޹Ʒþþþ| ˾þó˳ۺ222| ŷ츾XXXXԾþþ| þþƷ91þۺ鶹| ƷŮþAV| һþaþþƷvrۺ| þҹӰ| AV12þ| þþþþ޾Ʒ| 99þùƷһ| 777þþƷһ| ŷһþþƷ޾Ʒþþþ | ɫݺȷӰþ| þ99Ʒþ99С˵| ƷþþþþóAV| þóСƵ| 99þù뾫ƷѾþþþ| þAV뾫Ʒɫҹ | ޹˾þۺ| 91þùۺϾƷ| Ʒþþþþ | 99þۺϾƷ| re99þþƷ99| þһѵ | 뾫Ʒþþɫ | þۺһ| þþƷӰԺ| 99þóĻ| Ʒ˾þô߽ɫҳ| þۺɫˮ99ž| ŷպĻþþò| ھƷþþþþĻ| 99þþùƷţ | þ99Ʒþ99| պavþþƷ| ҹþþƷ|