proc_open(): fork failed-can not allocate memory, error on aws ec2 instance while updating/installing some libraries or packages using composer

Ziaur Rahman
Nov 3 · 4 min read
swap problem page

Introduction:
Firstly we have to understand why this error occurs? If we understand the problem then it is very easy to solve the problem. While we create instances on a cloud platform, we notice lot of parameters to decrease the bill and as well as performance should remain fantastic. Actually if the instance produces no bill, it is tremendous for us. With considering these parameters, generally we create an instance with a very small amount of memory. When we configure our project, then lots of libraries/packages needed to configure the project. These libraries/packages take a bunch of memories. While there is not enough memories then the error “proc_open(): fork failed-can not allocate memory” arises.

Solution:
If we allocate some memory from ssd or hdd that would be used as ram that is needed to install/update some libraries/packages. It may solve the problem. In ubuntu we call it as ‘swap’. By adding swap space, we can solve the not allocating memory problem.

Adding swap space:

Step1: At the beginning we need to check if there is any configuring swap by running the command. If there is no result on the screen. it means that there is no configured swap space.

$ sudo swapon — show

Step2: If you want to see your memory stats. You can run the command. you will see swap memory is 0B.

$ free -h

memory status of the pc

Step3: Observing all memory status to allocate swap

$ df -h

storage status

Step4: preparing a 1G size swap file in the root directory by using fallocate program by running the command.

$ sudo fallocate -l 1G /swapfile

allocating 1GB ram for swapfile and the permission

Step5: confirming the reserved space by running the command

$ ls -lh /swapfile

Step6: making /swapfile accessible by the command

$ sudo chmod 600 /swapfile

Again run the step5 command to see the permission directory. it will make you confirm and satiated.

checking the permission of the directory

Step7: making the swapfile as swap space by the command

$ sudo mkswap /swapfile

setting the swap space

Step8: enabling swapfile to utilize by the command

$ sudo swapon /swapfile

Step9: to see status of swap space by typing the command to see available swap space

$ sudo swapon — show

$ free -h

Step10: making the swapfile permanent. Our swapfile has been enabled to utilize. if we reboot/restart then it will flash/remove. To do permanent this we need to put the file into /etc/fstab directory by running the command

$ sudo cp /etc/fstab /etc/fstab.bak

$ echo ‘/swapfile none swap sw 0 0’ | sudo tee -a /etc/fstab

Step11: adjusting swappiness parameters. to see the swappiness value run the command

$ cat /proc/sys/vm/swappiness

to assign a value with swappiness run the command

$ sudo sysctl vm.swappiness=12

to set the value permanently run the command

$ sudo nano /etc/sysctl.conf

and write the value below of the file as vm.swappiness=12 and press ‘cltr + x’ and ‘shift + Y’ and ‘enter’ button to save.

Step12: adjusting swappiness cache pressure by typing the command

$ cat /proc/sys/vm/vfs_cache_pressure

to change the value run the command

$ sudo sysctl vm.vfs_cache_pressure=55

to set the value permanently run the command

$ sudo nano /etc/sysctl.conf

and write the value below of the file as vm.vfs_cache_pressure=55 and press ‘cltr + x’ and ‘shift + Y’ and ‘enter’ button to save.

save and close the when finishing the edition. Now your swap file has been created.

And now run that command for what you saw the error,

solution page

it may vanish……………..whoaaaaaaaaa


Originally published at http://zrshishir.blogspot.com.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade