Linux restricts the CPU usage of user processes-Linux Enterprise applications-Linux server application information. The following is a detailed description. I have searched a lot of materials and I don't have a good answer to this question. Most of them are using pam to limit user resources. One of them is the CPU time, but there is no CPU usage.
In fact, it is acceptable for a user process to run for a long time on a linux server. If the CPU usage is too high, other users will not be able to bear it, but it is likely that there is a problem with the user program. At this time, the system should automatically stop such a process from consuming system resources.
The simplest method is to discover a user process with CPU usage exceeding a certain limit through ps and then kill the process. This is very violent, the user finds that the process is likely to start again after it is killed, which is a vicious circle.
There is a way to compromise, instead of killing the target process, but adjusting its nice value as appropriate. For details, see the following shell program: