跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] 我写了一个堪称愚蠢的小工具

发表于

不知道各位有没有那种需要起一个程序占用特定 CPU 和内存的需求,我最近是有。在公司的一个需求自测的时候,需要设置「 CPU 告警阈值」和「内存告警阈值」,然后通过占用 CPU 和内存的方式触发告警。

之前占用 CPU 我都是开一个 Python Console 然后计算 999999999999999 ** 99999999999999999,虽然能用但非常不优雅:每个 Python 进程只能占用 1 个核心且不能占用 0.5 个核心。内存则是 dd if=/dev/zero of=output_file bs=4k count=xxx 来生成一个固定大小的文件,然后用 Python open('output_file').read(),同样是又麻烦又不优雅。

所以开发了这个叫 eat 的小工具,可以通过下面的命令占用指定的 CPU 和内存数量

eat -c 4            # 占用 4 个 CPU 核
eat -c 100%         # 占用所有 CPU 核
eat -m 4g           # 占用 4GB 内存
eat -m 20m          # 占用 20MB 内存
eat -m 100%         # 占用所有内存
eat -c 2.5 -m 1.5g  # 占用 2.5 个 CPU 核和 1.5GB 内存
eat -c 3 -m 200m    # 占用 3 个 CPU 核和 200MB 内存
eat -c 100% -m 100% # 占用所有 CPU 核和内存

贴上 GitHub 地址各位有兴趣可以试一下~

Featured Replies

No posts to show

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.