当前位置: 首页> 英语翻译> 正文

confining是什么 confining的翻译

  • 作者: 用户投稿
  • 2023-04-14 11:39:08
  • 42

Confining是一种计算机技术,它可以限制应用程序的权限,以防止其恶意行为。它通常使用Linux内核中的namespaces和cgroups功能来实现。

1. 命名空间:命名空间是一种技术,它可以将一个进程隔离到一个独立的环境中,使其不会影响其他进程或系统。例如,可以使用Linux的PID命名空间来限制一个进程的PID范围,以防止其访问其他进程的资源。

代码示例:

#include#include#include#include#include#include/* 定义一个给 clone 用的栈,栈大小1M */ #define STACK_SIZE (1024 * 1024) static char container_stack[STACK_SIZE]; char* const container_args[] = { "/bin/bash", NULL }; int container_main(void* arg) { printf("Container - inside the container!\n"); /* 直接执行一个shell,以便我们观察这个进程空间里的资源是否被隔离了 */ execv(container_args[0], container_args); printf("Something's wrong!\n"); return 1; } int main() { printf("Parent - start a container!\n"); /* 调用clone函数,其中传出一个函数,还有一个栈空间的(为什么传尾指针,因为栈是反着的) */ int container_pid = clone(container_main, container_stack+STACK_SIZE, CLONE_NEWUTS | SIGCHLD, NULL); waitpid(container_pid, NULL, 0); printf("Parent - container stopped!\n"); return 0; }

2. cgroups:cgroups是一种技术,可以限制特定进程的资源使用情况,例如CPU时间、内存使用量、磁盘I/O等。这样,可以确保即使在多个进程之间共享资源的情况下,也不会出现资源耗尽的情况。

代码示例:

#include#include#include#include#include#include#include#include#include#include#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) int main(int argc, char *argv[]) { pid_t child_pid; char *cmd; int fd; if (argc< 2) { fprintf(stderr, "Usage: %s cmd [arg...]\n", argv[0]); exit(EXIT_FAILURE); } cmd = argv[1]; argv += 1; setbuf(std
 
 
  • 3457人参与,13条评论