Outils pour utilisateurs

Outils du site


blog

16 billet(s) pour mai 2025

Notes memcache2025/05/27 12:51Jean-Baptiste
Vim comme éditeur par defaut2025/05/27 10:20Jean-Baptiste
Notes git et cerfificats HTTPS2025/05/26 15:47Jean-Baptiste
Notes réseaux2025/05/26 10:06Jean-Baptiste
Notes protocol FTP2025/05/22 15:31Jean-Baptiste
Notes Webasm Wasm WebAssembly2025/05/20 17:31Jean-Baptiste
Bash et Programmation Fonctionnelle2025/05/19 17:01Jean-Baptiste
Notes P2P2025/05/17 23:17Jean-Baptiste
Notes Python - programmation fonctionnelle - curry curryfication currying2025/05/17 14:14Jean-Baptiste
Notes Communication inter-processus RPC2025/05/15 12:13Jean-Baptiste
Notes nested virtualization2025/05/15 12:06Jean-Baptiste
Notes IPython derrière un reverse proxy2025/05/14 03:22Jean-Baptiste
Notes install IPython sous Android avec Termux2025/05/14 03:22Jean-Baptiste
Notes fichiers - binaire executable exe elf2025/05/06 14:48Jean-Baptiste
Notes HTML2025/05/03 10:02Jean-Baptiste
Notes IPFS2025/05/01 01:56Jean-Baptiste

Notes conversion JSON YAML

Voir :

Voir aussi :

# Source - https://stackoverflow.com/a/60585911
# Posted by Richard Gomes, modified by community. See post 'Timeline' for change history
# Retrieved 2026-11-13, License - CC BY-SA 4.0
 
function yaml_validate {
  python -c 'import sys, yaml, json; yaml.safe_load(sys.stdin.read())'
}
 
function yaml2json {
  python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))'
}
 
function yaml2json_pretty {
  python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read()), indent=2, sort_keys=False))'
}
 
function json_validate {
  python -c 'import sys, yaml, json; json.loads(sys.stdin.read())'
}
 
function json2yaml {
  python -c 'import sys, yaml, json; print(yaml.dump(json.loads(sys.stdin.read())))'
}

FIXME

2026/11/13 11:16 · Jean-Baptiste

Git commit perdu

git reflog
git checkout dev
git checkout 5559d8a .
# git reset --hard 5559d8a

FIXME

2026/11/12 18:16 · Jean-Baptiste

Notes mojo lang

Voir :

uv pip install mojo

hello.mojo

def main():
    print("Hello world !") 
mojo format hello.mojo
mojo run hello.mojo
mojo build hello.mojo
2026/11/11 20:34 · Jean-Baptiste

Notes rust lang compilation

Voir :

sudo apt-get install cargo
cargo new hello-world
 
cd hello-world/

src/main.rs

fn main() {
    println!("Hello, world!");
}

Compilation

Compilation basique

rustc src/main.rs

Compilation statique

sudo apt-get install librust-rustup-dev rustup
rustup default stable
rustup target add x86_64-unknown-linux-musl
cargo build --target=x86_64-unknown-linux-musl
$ ldd ./target/x86_64-unknown-linux-musl/debug/hello-world
        statically linked

Compilation 32bits pour windows

rustup target add i686-pc-windows-gnu
cargo build --target=i686-pc-windows-gnu
# cargo build  --release --target=i686-pc-windows-gnu
wine target/i686-pc-windows-gnu/debug/hello-world.exe

Compilation 32bits statique pour GNU/Linux

rustup target add i686-unknown-linux-musl
cargo build --target i686-unknown-linux-musl
2026/11/11 18:35 · Jean-Baptiste

Mémoire VSIZE VMSIZE SEGV lang C

Voir :

Erreur ENOMEM (Cannot allocate memory)

malloc_only.c

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
int main(ulong argc, char **argv) {
  ulong i, size_max, block_size;
 
  size_max = atoi(argv[1]);
  for (i = 0; i < size_max; i++) {
    block_size = 1024 * 1024;
    int *ptr = malloc(sizeof(int) * block_size);
    if (ptr == NULL) {
      printf("ERROR: Bad allocation at %lu\n", i);
      exit(EXIT_FAILURE);
    }
    // free(ptr);
    // ptr = NULL;
  }
  printf("%lu\n", i);
  pause();
}

Simuler une fuite d'allocation mémoire. Process avec une VMSIZE en constante augmentation jusqu'au max donné en argument

malloc_only_grow.c

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
int main(ulong argc, char **argv) {
  ulong i, size_max, block_size;
 
  size_max = atoi(argv[1]);
  for (i = 0; i < size_max; i++) {
    printf("%lu\n", i);
    block_size = 1024 * 1024;
    int *ptr = malloc(sizeof(int) * block_size);
    if (ptr == NULL) {
      printf("ERROR: Bad allocation at %lu\n", i)
      exit(EXIT_FAILURE);
    }
 
    sleep(1);
  }
}

malloc_bad.c

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(int argc, char **argv) {
  int block_size = atoi(argv[1]);
  int *ptr = malloc(sizeof(int) * block_size * 1024);
  if (ptr == NULL) {
    printf("ERROR: Bad allocation\n");
    // exit(EXIT_FAILURE);
  }
 
  memset(ptr, 0, block_size);
}

malloc_usemem.c

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
int main(ulong argc, char **argv) {
  ulong i, size_max, block_size;
 
  size_max = atoi(argv[1]);
  for (i = 0; i < size_max; i++) {
    block_size = 1024 * 1024;
    int *ptr = malloc(sizeof(int) * block_size);
    if (ptr == NULL) {
      printf("ERROR: Bad allocation at %lu\n", i);
      exit(EXIT_FAILURE);
    }
    memset(ptr, 0, block_size);
    // free(ptr);
    // ptr = NULL;
  }
  printf("%lu\n", i);
  pause();
}

Cross-compilation 32 bits

i686-linux-gnu-gcc -static malloc_bad.c -o malloc_bad.bin
i686-linux-gnu-gcc -static malloc_only.c -o malloc_only.bin
i686-linux-gnu-gcc -static malloc_usemem.c -o malloc_usemem.bin
ps -eo pid,ppid,start,rsz,vsz,cmd 
$ awk '/^Size/ { sum += $2 } END { print sum }' /proc/93035/smaps
4141964

$ ps -p 93035 --no-headers -o vsz
4141964

$ cat /proc/93035/status | grep -E "VmSize|VmRSS|VmPeak|VmHWM"
VmPeak:  4141964 kB
VmSize:  4141964 kB
VmHWM:      4680 kB
VmRSS:      4680 kB

Corrections

  1. Vérifiez toujours le retour de malloc
int *ptr = malloc(sizeof(int) * 10);
if (ptr == NULL) {
    // Gestion de l'erreur (pas assez de mémoire)
    exit(EXIT_FAILURE);
}
  1. Vérifiez les tailles passées à malloc : Assurez-vous de multiplier par sizeof(type) et non par une variable erronée.
  2. Utilisez un outil de débogage : Exécutez votre programme avec valgrind (sous Linux) ou un débogage pas-à-pas (GDB) pour identifier la ligne exacte qui provoque le crash.

Autres

VMSIZE : Tout l'espace d'adressage virtuel réservé par le processus, ce qui comprend le code exécutable, les données, la pile (stack), le tas (heap), ainsi que les bibliothèques partagées et les zones mappées en mémoire (qu'elles soient réellement chargées en RAM physique ou non)

VMSIZE et nombre de threads

En cas de fuite de vmsize, regarder le nombre de threads pour savoir si cela pourrait être la cause.

La virtual stack size est souvent de 8 MiB

Voir

Voir ulimit -s ou

$ ulimit -a | grep stack
stack size                  (kbytes, -s) 8192
ps -o pid,ppid,pcpu,rss,size,vsize,cputime,lstart -Lp 31861

Si un thread a besoin de plus de mémoire sur la pile, alors un “page fault” est effectué par la MMU, c'est transparent.

Voir https://unix.stackexchange.com/questions/127602/default-stack-size-for-pthreads

2026/11/11 15:59 · Jean-Baptiste
blog.txt · Dernière modification : de 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki