github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/cmd/oom/main.go (about)

     1  // Copyright 2019 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"flag"
     9  	"fmt"
    10  	"log"
    11  	"os"
    12  
    13  	"github.com/Schaudge/grailbase/stress/oom"
    14  )
    15  
    16  func main() {
    17  	log.SetFlags(0)
    18  	log.SetPrefix("oom: ")
    19  	size := flag.Int("size", 0, "amount of memory to allocate; automatically determined if zero")
    20  
    21  	flag.Usage = func() {
    22  		fmt.Fprintf(os.Stderr, `usage: oom [-size N]
    23  
    24  OOM attempts to OOM the system by allocating up
    25  N bytes of memory. If size is not specified, oom
    26  automatically determines how much memory to allocate.
    27  `)
    28  		os.Exit(2)
    29  	}
    30  	flag.Parse()
    31  	if *size != 0 {
    32  		oom.Do(*size)
    33  	}
    34  	oom.Try()
    35  }