process and cgroups

process and cgroups

Process and CGroups.

Using CGroups we can limit maximum amount of RAM and CPU can be consumed by a process.

Without creating a CGroup we can directly start a process with certain limits using systemd-run

sudo systemd-run --scope -p CPUQuota=10% -p MemoryMax=500M <process_name>

if want it more static, you can create a cgroup and configure limits then map the process ID to that Cgroup.

Create a new cgroup and set limits

laborant@ubuntu-01:~$ sudo mkdir /sys/fs/cgroup/my_custom_limit
laborant@ubuntu-01:~$ echo "+cpu +memory" | sudo tee /sys/fs/cgroup/cgroup.subtree_control
+cpu +memory
laborant@ubuntu-01:~$ cd /sys/fs/cgroup/my_custom_limit
laborant@ubuntu-01:my_custom_limit$ echo "500M" | sudo tee memory.max
500M
laborant@ubuntu-01:my_custom_limit$ echo "1
0000 100000" | sudo tee cpu.max # 10% of CPU
10000 100000

Memory.max vs .high

sudo tee memory.max -> the moment process reaches its limit, its get killed by OOM
sudo tee memory.high -> before this limit reached, memory utilizaition will be throttled to avoid killing.

Already running process

  • you can map a process to a cgroup which you created
laborant@ubuntu-01:my_custom_limit$ omnihog  > /dev/null & 
[1] 2545
laborant@ubuntu-01:my_custom_limit$ echo 2545 | sudo tee cgroup.procs
2545

Launch a shell so any new process under it get these limits applied

or you can launch new shell inside of that cgroup and then you can start the process, so that process will be applied those cgroup limits

laborant@ubuntu-01:my_custom_limit$ echo $$ | sudo tee cgroup.procs
1027
laborant@ubuntu-01:my_custom_limit$ omnihog 
[2026-10-29T12:25:30] Started a CPU hog
[2026-10-29T12:25:30] Started a CPU hog
[2026-10-29T12:25:30] Started a CPU hog
[2026-10-29T12:25:30] Started a CPU hog
[2026-10-29T12:25:31] Allocated 10 MB of memory
[2026-10-29T12:25:33] Allocated 10 MB of memory
[2026-10-29T12:25:35] Allocated 10 MB of memory
....
[2026-10-29T12:26:41] Allocated 10 MB of memory
Killed
laborant@ubuntu-01:my_custom_limit$ 

That’s it, and hope it helps.
Thank you.

azure create vm

Azure CLI Commands & Practice Workflow

1. Retrieve Resource Group Name

Query the first available resource group and output as tab-separated values (tsv) to strip quotes and extra formatting:

Bash

rg_name="$(az group list --query '[0].name' -o tsv)"

2. Create Key Vault Certificate

Create a new certificate using Azure Key Vault’s default policy:

Bash

az keyvault certificate create \
  --vault-name vaultname \
  -n cert1 \
  -p "$(az keyvault certificate get-default-policy)"

3. Retrieve Secret Version IDs

Get all enabled secret version IDs associated with the certificate:

Bash

secrets=$(az keyvault secret list-versions \
  --vault-name vaultname \
  -n cert1 \
  --query "[?attributes.enabled].id" \
  -o tsv)

4. Format Secret for VM Deployment

Format the secret ID to prepare it for attachment during VM creation:

Bash

vm_secrets=$(az vm secret format -s "$secrets")

5. Create Virtual Machine

Command Syntax

Bash

az vm create \
  -n nautilus-vm \
  -g $rg_name \
  --image Ubuntu2204 \
  --size Standard_DS2_v2 \
  --admin-username azureuser \
  --generate-ssh-keys \
  --data-disk-sizes-gb 30 \
  --storage-sku Standard_LRS

Command Execution

Bash

az vm create \
  -n nautilus-vm \
  -g kml_rg_main-01cde7595e7b4e3e \
  --image Ubuntu2204 \
  --size Standard_B2s \
  --admin-username azureuser \
  --generate-ssh-keys \
  --data-disk-sizes-gb 30 \
  --storage-sku Standard_LRS

Creation Output

JSON

{
  "fqdns": "",
  "id": "/subscriptions/f0c3bcdd-5ce2-4fa0-8cf3-41559747512b/resourceGroups/kml_rg_main-01cde7595e7b4e3e/providers/Microsoft.Compute/virtualMachines/nautilus-vm",
  "location": "eastus",
  "macAddress": "00-22-48-2B-7F-E6",
  "powerState": "VM running",
  "privateIpAddress": "10.0.0.4",
  "publicIpAddress": "20.25.33.164",
  "resourceGroup": "kml_rg_main-01cde7595e7b4e3e",
  "zones": ""
}

6. List Virtual Machines (Table Output)

List all VMs with details including Power State and Provisioning State in a formatted table:

Bash

az vm list -d --query "[].{Name:name, ResourceGroup:resourceGroup, PowerState:powerState, ProvisioningState:provisioningState}" -o table

GoLang_System_Essentials_Notes_Chapter_1

Why Go

Apart from easy to read code and simple learning curve which encourages everyone to quickly adopt the existing code system, Go has a very strong concurrency model.

Concurrency defines throughput of your system. When a task is waitnig for I/O resources, if you can code like other task can leverage the idle CPU, then throughput of your entire program will be increased.

Go uses channels for communicating between threads and go follows CSP when it comes to implementation of threads and thread communication.
There is an excellent paper written on same. https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf

And another prinicple, share memory not by locks but by communicating. We can write a lot about go concurrency, but lets see in practicals.

Go in-built tools

go build main.go to generate go binary
go test to run tests
go run main/hello.go to run your program but no binary generation
go vet filename.go to check errors in your code.
go fmt file.go to format your go code.

Cross platform development

two main env variables, GOOS and GOARCH
GOOS for OS Target
GOARCH for CPU arch, amd64, darwin etc
Linux build command
GOOS=linux GOARCH=amd64 go build
For Mac
GOOS=darwin GOARCH=amd64 go run

We can also add build tags for specific platform

// go:build windows
package main
import "fmt"
func main() {
    fmt.Println("This is Windows!")
}
// go:build linux
package main
import "fmt"
func main() {
    fmt.Println("This is Linux!")
}
GOOS=windows go build -o app.exe
GOOS=linux go build -o app

Linux: Firefox in Debian+I3m taking a lot of time to load

 Recently, Firefox in my Linux setup( Debian + i3wm) taking a lot of time to reload. Upon searching I came to know that its caused by xdg-desktop-portal package. From Arch docs I understand that its for opening the application in a sandbox environment for better safety and then I thought no security needed for Firefox if its not there for Chrome. 

So I remove it. 

 
  sudo apt-get remove xdg-desktop-portal
 

Hope it helps.

How to fix Microsoft Blue Death Of Screen(BDOS) issue ?

Many Microsoft Windows users are experiencing Blue Screen of Death (BSOD) errors following a recent CrowdStrike update.

1) Boot Windows into Safe Mode

2) Navigate to the directory C:\Windows\System32\drivers\CrowdStrike

3) Locate the file matching C-00000291*.sys and delete it

4) Boot the host normally

Note: You can also boot in Windows Recovery Environment (WinRE)