Limiting CPU Usage of A Process in CentOS/RHEL 7

In HPC, we may need to protect head node from unnecessary heavy process that may cause login problem for users. One of the solutions is by using cpulimit. We can create a cronjob to monitor all processes and set certain limit for them. This is how I usually did in CentOS/RHEL 7.x.

  1. Install cpulimit package from EPEL repo.

yum install cpulimit

  1. Create a script to monitor the process. The script below is a modified version of the script in this forum. You can modify inputs of the first 3 variables: CPU_LIMIT, BLACK_PROCESSES_LIST, and WHITE_PROCESSES_LIST.

Read More …

process and fork()

Process is a program in execution. Process execution must progress in sequential fashion. A process includes program counter, stack, and data section. In UNIX, a process is created by fork() system call. Below is the main fork() program based on C language.

[sourcecode language=’cpp’]

int main()
pid_t pid = fork();

if (pid < 0)
/*error occured*/
fprintf(stderr,"error forking childn");
else if (pid == 0)
/*child process*/
/* put your application here*/
/*parent process*/
int status;
/*wait for child process to complete*/
/*when child process has been completed, */
/*it will return status 0 */


You may download a sample application to count fibonacci sequence that uses fork() system call,