ulimit 命令使用说明

aarch32  linux4.14  busybox v1.29

ulimits are per-process, not per-user nor per-system.

The ulimit command is built into the shell, so it remains within the same process; however, the adjusted limit only affects that process, as well as everything you run from it (child processes inherit the same limits).

busybox sh -c 'ulimit -c unlimited'

 

soft limit hard limit

 

#include 

int getrlimit(int resource, struct rlimit *rlim);
int setrlimit(int resource, const struct rlimit *rlim);
$ cat /proc//limits
Limit               Soft Limit  Hard Limit  Units 
Max cpu time        unlimited   unlimited   seconds
Max file size       unlimited   unlimited   bytes 
Max data size       unlimited   unlimited   bytes
Max stack size      10485760    unlimited   bytes
Max core file size  0           unlimited   bytes
Max resident set    unlimited   unlimited   bytes
Max processes       3515        3515        processe
Max open files      1024        4096        files   
Max locked memory   65536       65536       bytes   
Max address space   unlimited   unlimited   bytes  
Max file locks      unlimited   unlimited   locks  
Max pending signals 3515        3515        signals
Max msgqueue size   819200      819200      bytes
Max nice priority   0           0           
Max realtime priority 0         0                    
Max realtime timeout  unlimited unlimited   us
#include 
#include 
#include 

static void sub(void);

int main(void)
{
    struct rlimit lim = {0, 0}; 
    int ret;
    ret = getrlimit(RLIMIT_CORE, &lim);
    printf("get rlimit ret %d\n",ret);
    if(ret !=0 ){
        printf("read rlimit failed\n");
        return 0;
    }   
    
    printf("get limit cur %lu max %lu\n",lim.rlim_cur, lim.rlim_max);

    lim.rlim_cur = RLIM_INFINITY;
    lim.rlim_max = RLIM_INFINITY;

    ret = setrlimit(RLIMIT_CORE, &lim);
    printf("set rlimit ret %d\n",ret);
    if ( ret != 0) {
        printf("rlimit failed\n");
        return 0;
    }   
        
    ret = getrlimit(RLIMIT_CORE, &lim);
    printf("get rlimit ret %d\n",ret);
    if(ret !=0 ){
        printf("read rlimit failed\n");
        return 0;
    }   
        
    printf("get limit cur %lu max %lu\n",lim.rlim_cur, lim.rlim_max);

    sub();  
    return 0;  
}  

static void sub(void)
{
    int *p = NULL;
    /* derefernce a null pointer, expect core dump. */
    sleep(20);
    printf("%d", *p);
}                                                                                                                                                           
配置生成的core文件的名称与路径

echo /sdcard/core-%e-%p-%t > /proc/sys/kernel/core_pattern
%e -- excute name
%p -- pid
%t -- timestamp

 

你可能感兴趣的:(LINUX,C语言)