judge: terminal: show memory limit

This commit is contained in:
undefined committed 2024-04-06 23:33:48 +08:00
1 parent 246485c7b4
commit 1916231f9d
1 file changed
+7 -4
+7 -4
View File
@@ -1,3 +1,4 @@
import os from 'os';
import log from './log'; import log from './log';
import client from './sandbox/client'; import client from './sandbox/client';
@@ -11,17 +12,19 @@ export = async function terminal() {
log.error('interactive terminal requires available tty'); log.error('interactive terminal requires available tty');
return; return;
} }
const memoryLimit = Math.floor(os.totalmem() / 4);
process.stdin.setRawMode(true); process.stdin.setRawMode(true);
log.info('Starting /bin/bash, double press Ctrl+C to kill all child processes.'); log.info('Starting /bin/bash, double press Ctrl+C to kill all child processes.');
log.info(`Current memory limit is ${Math.floor(memoryLimit / 1024 / 1024)}m`);
const stream = client.stream({ const stream = client.stream({
cmd: [{ cmd: [{
args: ['/bin/bash'], args: ['/bin/bash'],
env: ['PATH=/usr/local/bin:/usr/bin:/bin', 'HOME=/tmp', `TERM=${process.env['TERM']}`], env: ['PATH=/usr/local/bin:/usr/bin:/bin', 'HOME=/tmp', `TERM=${process.env['TERM']}`],
files: [{ streamIn: true }, { streamOut: true }, { streamOut: true }], files: [{ streamIn: true }, { streamOut: true }, { streamOut: true }],
cpuLimit: (20 * 1e9), cpuLimit: (120 * 1e9),
clockLimit: (30 * 60 * 1e9), clockLimit: (30 * 120 * 1e9),
memoryLimit: (256 << 20), memoryLimit,
procLimit: 50, procLimit: 128,
tty: true, tty: true,
}], }],
}); });