Outils pour utilisateurs

Outils du site


blog

18 billet(s) pour avril 2026

Go lang - if x in list2026/04/29 18:42Jean-Baptiste
Pascal Lazarus - Compilation croisée dans un conteneur2026/04/27 23:31Jean-Baptiste
script - subshells sous-shells - comportement déroutant de bash qu'un débutant doit connaître2026/04/25 11:16Jean-Baptiste
Go lang - compiler pour windows i386 32bits2026/04/23 19:32Jean-Baptiste
Réseau - Forger un paquet TCP UDP ou autre2026/04/22 10:20Jean-Baptiste
Wine Err bcryptprimitives.dll not found - Compilation Croisée Go lang2026/04/21 23:16Jean-Baptiste
Makefile et variables d'environnement2026/04/21 22:06Jean-Baptiste
Err Go lang et langage C2026/04/21 21:07Jean-Baptiste
Notes fichiers so linux - compiled library file - shared object file2026/04/20 21:12Jean-Baptiste
Notes windows EXE DLL2026/04/19 22:39Jean-Baptiste
Inclure ASM dans Go lang2026/04/19 02:27Jean-Baptiste
Inclure du C dans Go lang2026/04/19 01:32Jean-Baptiste
Création image conteneur - exemple de multi-stage builds2026/04/18 17:07Jean-Baptiste
Exécuter du code python avec go lang2026/04/18 17:00Jean-Baptiste
Inclure des appels à Go lang dans Python2026/04/18 16:14Jean-Baptiste
Notes protocoles TCP/IP - IGMP et multicast2026/04/15 09:42Jean-Baptiste
Notes go lang programmation fonctionnelle2026/04/13 22:27Jean-Baptiste
Notes ping ICMP2026/04/03 23:01Jean-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