Crond多次执行shell

时间:2015-07-02 02:44:30

标签: shell cron

我在RedHat 2.6.32 x86_64中有以下timey.cpp代码:

using namespace std ;
int main()
{
    while( 1 ){
        char x[64]={0} ;
        strcpy( x,"1234567890") ;
        std::string s = x ;
        std::cout << "(" <<  x << ")" << std::endl ;
        struct timeval localtimex ;
        long secs,usecs ;
        gettimeofday(&localtimex,0x00) ;
        secs  = localtimex.tv_sec ;
        usecs = localtimex.tv_usec ;
        //long mills = (time.tv_sec * 1000) + (time.tv_usec / 1000 ) ;
        printf("secs=(%d),usecs=(%d)\n",secs,usecs) ;
        sleep( 1 ) ;
    } //while 
}
/home/informix/test中的

,由g++ --std=c++0x timey.cpp -o timey.exe编译, shell timey.sh

    source /etc/bashrc
    nohup /home/informix/test/timey.exe &

然后我通过以下方式运行timey.sh

    /home/informix/test/timey.sh

并查看timey.exe是否按以下方式运行:

    ps -ef | grep timey

似乎timey.exe按预期运行:

    informix 41340     1  0 10:32 pts/10   00:00:00 /home/informix/test/timey.exe

令我困惑的是我将此shell添加到crontab:

    38 10 * * 1-5 informix /home/informix/test/timey.sh

并重新启动crond

    /etc/init.d/crond restart

令我惊讶的是,我看到timey.exe正在运行的4份副本:

    ps -ef | grep timey
    informix 41498     1  0 10:38 ?        00:00:00 /home/informix/test/timey.exe
    informix 41499     1  0 10:38 ?        00:00:00 /home/informix/test/timey.exe
    informix 41529     1  0 10:38 ?        00:00:00 /home/informix/test/timey.exe
    informix 41561     1  0 10:38 ?        00:00:00 /home/informix/test/timey.exe

我做错了什么才能运行4份timey.exe

我在/var/log/cron中看到以下内容:

Jul  2 10:38:01 localhost CROND[41440]: (informix) CMD (/home/informix/test/timey.sh )
Jul  2 10:38:01 localhost CROND[41439]: (informix) CMD (/home/informix/test/timey.sh )
Jul  2 10:38:01 localhost CROND[41491]: (informix) CMD (/home/informix/test/timey.sh )
Jul  2 10:38:01 localhost CROND[41533]: (informix) CMD (/home/informix/test/timey.sh )

crond似乎真的跑了timey.sh 4次,但为什么?

此外:

  • 在RedHat 2.6.32-279.el6.x86_64中,它有效!
  • 在RedHat 2.6.32-358.el6.x86_64中,它不起作用!

0 个答案:

没有答案