首页 > 解决方案 > 我可以在树莓派上同时运行多少个 py 脚本?

问题描述

我知道您可以使用不同的终端运行多个脚本,但必须有一个限制。我不能只在一个小 pi 上运行一百万个。所以真正的问题......有没有办法可以检查我的脚本有多苛刻。先感谢您!

pi 零 w / python 3

标签: pythonraspberry-pi

解决方案


忽略内存和 CPU 消耗带来的明显限制,如果您在 Raspberry PI 上运行基于 Linux 的操作系统,您可以检查/proc/sys/kernel/pid_max. 从手册页

/proc/sys/kernel/pid_max (since Linux 2.5.34)
          This file specifies the value at which PIDs wrap around (i.e.,
          the value in this file is one greater than the maximum PID).
          PIDs greater than this value are not allocated; thus, the
          value in this file also acts as a system-wide limit on the
          total number of processes and threads.  The default value for
          this file, 32768, results in the same range of PIDs as on ear‐
          lier kernels.  On 32-bit platforms, 32768 is the maximum value
          for pid_max.  On 64-bit systems, pid_max can be set to any
          value up to 2^22 (PID_MAX_LIMIT, approximately 4 million).

换句话说:在大多数默认配置下,Linux 最多可以同时运行 32,768 个进程(和线程,加起来)。请注意,您正在与系统上运行的所有其他东西共享这些 PID,包括操作系统本身的部分。

因此,假设您默认运行 150 个进程和线程,并且您的脚本使用的 CPU 和内存量可以忽略不计,并且只有一个线程,那么您最多可以同时运行 32,618 个脚本实例。


推荐阅读