Table des matières
- 2026:
- 2025:
9 billet(s) pour avril 2025
| Notes geoip | 2025/04/30 14:49 | Jean-Baptiste |
| Générateur de conf Nagios | 2025/04/18 11:17 | Jean-Baptiste |
| Err ssh - Authentication refused bad ownership or modes for directory | 2025/04/15 15:26 | Jean-Baptiste |
| Notes NSClient (Agent Nagios / Centreon pour windows) | 2025/04/15 15:22 | Jean-Baptiste |
| Monter un ficher VMDK | 2025/04/09 15:59 | Jean-Baptiste |
| Lancer des applications Android sous GNU Linux | 2025/04/07 14:15 | Jean-Baptiste |
| Note crack ASM Assembly reverse | 2025/04/04 17:44 | Jean-Baptiste |
| Pb plugin Nagios centreon NSClient 403 | 2025/04/04 14:18 | Jean-Baptiste |
| Prometheus windows_export i386 compilation go lang | 2025/04/03 14:09 | Jean-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())))' }
Git commit perdu
git reflog git checkout dev git checkout 5559d8a . # git reset --hard 5559d8a
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
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
Mémoire VSIZE VMSIZE SEGV lang C
Voir :
- /proc/$PID/statm
- /proc/$PID/smaps
- /proc/$PID/smaps_rollup
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
- 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); }
- Vérifiez les tailles passées à malloc : Assurez-vous de multiplier par sizeof(type) et non par une variable erronée.
- 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
man pthread_create
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
