Question

I am trying to convert a csh script to a tcl script for use within the linux modules functionality. The csh script was originally used to set environment variables properly for a software package. Instead of asking an end-user to change his shell and run 3 commands every time he/she wishes to use the software, I wanted to create a simple one-line command that is shell independent and sets up the their environment appropriately. As such, using modulefile seems like the perfect way to accomplish this.

My problem arises when I try to set a limit on the coredumpsize, as there doesn't appear to be any way to set this value from within modules. The original csh command looks like this, limit coredumpsize 0. I understand that the original bash command line equivalent of this is, ulimit -c 0. Note: Both of these commands assume that I want to disable coredumpfiles while using this software.

My modulefile code tries to invoke this command in a shell-dependent manner, b/c there doesn't appear to be a "limit" command native to modulefiles.

set shell [module-info shell]
if { $shell=="bash"} {
    set XARCH amd64
    [exec /bin/bash -c "ulimit -c 0"]
} elseif {$shell=="tcsh"} {
    set XARCH linux
    [exec /bin/tcsh -c "limit coredumpsize 0"]

Based on my web-wide research, I can't find an environment variable that I can modify, although RLIMIT_CORE looks like it might be close to what I'm looking for. The problem w/ my current code is that the exec command spawns a process of $shell and runs the one command, as opposed to running the limit command on the shell that called the tcl module process.

Any help would be much appreciated for being able to change the environment variables and setting the limit for the coredumpsize in one simple way, ideally using modules.

Was it helpful?

Solution

You cannot set limits by running a shell, because that limit will only affect the shell process you created (and not the tcl process itself).

You need to find out how to call the setrlimit(2) syscall directly. Perhaps tclx might help.

Take several hours to read Advanced Linux Programming.

You are misunderstanding some fundamental Unix concepts, notably processes.

OTHER TIPS

module evaluates on currently running shell what modulefile evaluation produces on stdout.

The following ulimit modulefile should help to set apply a given ulimit configuration on currently running shell

#%Module

switch -- [module-info shelltype] {
    {sh} {
        puts stdout "ulimit -c 0"
    }
    {csh} {
        puts stdout "limit coredumpsize 0"
    }
}

Loading modulefile we can check ulimit configuration has been changed on current shell:

$ ulimit -c
unlimited
$ module -V
Modules Release 4.1.3 (2018-06-18)
$ module load ./ulimit
$ ulimit -c
0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top