当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Setrlimit函数代码示例

本文整理汇总了Golang中syscall.Setrlimit函数的典型用法代码示例。如果您正苦于以下问题:Golang Setrlimit函数的具体用法?Golang Setrlimit怎么用?Golang Setrlimit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Setrlimit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: SetLimits

// SetLimits raises some process limits to values which allow dcrd and
// associated utilities to run.
func SetLimits() error {
	var rLimit syscall.Rlimit

	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return err
	}
	if rLimit.Cur > fileLimitWant {
		return nil
	}
	if rLimit.Max < fileLimitMin {
		err = fmt.Errorf("need at least %v file descriptors",
			fileLimitMin)
		return err
	}
	if rLimit.Max < fileLimitWant {
		rLimit.Cur = rLimit.Max
	} else {
		rLimit.Cur = fileLimitWant
	}
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		// try min value
		rLimit.Cur = fileLimitMin
		err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:decred,项目名称:dcrd,代码行数:34,代码来源:limits_unix.go

示例2: TestRlimit

func TestRlimit(t *testing.T) {
	var rlimit, zero syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
	if err != nil {
		t.Fatalf("Getrlimit: save failed: %v", err)
	}
	if zero == rlimit {
		t.Fatalf("Getrlimit: save failed: got zero value %#v", rlimit)
	}
	set := rlimit
	set.Cur = set.Max - 1
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set)
	if err != nil {
		t.Fatalf("Setrlimit: set failed: %#v %v", set, err)
	}
	var get syscall.Rlimit
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &get)
	if err != nil {
		t.Fatalf("Getrlimit: get failed: %v", err)
	}
	set = rlimit
	set.Cur = set.Max - 1
	if set != get {
		t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get)
	}
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
	if err != nil {
		t.Fatalf("Setrlimit: restore failed: %#v %v", rlimit, err)
	}
}
开发者ID:ds2dev,项目名称:gcc,代码行数:30,代码来源:rlimit_linux_test.go

示例3: setResourceLimits

func setResourceLimits() error {
	const maximumTimeInSeconds = 5
	limit := syscall.Rlimit{maximumTimeInSeconds, maximumTimeInSeconds}
	if err := syscall.Setrlimit(syscall.RLIMIT_CPU, &limit); err != nil {
		return err
	}
	const maximumMemoryInBytes = 1 << 28
	limit = syscall.Rlimit{maximumMemoryInBytes, maximumMemoryInBytes}
	return syscall.Setrlimit(syscall.RLIMIT_AS, &limit)
}
开发者ID:ROM-PacMe,项目名称:skia,代码行数:10,代码来源:fiddler.go

示例4: registerSync

func registerSync(container, local, remote string) error {
	syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{
		Max: 999999,
		Cur: 999999,
	})

	abs, err := filepath.Abs(local)

	if err != nil {
		return err
	}

	sym, err := filepath.EvalSymlinks(abs)

	if err != nil {
		return err
	}

	syncs = append(syncs, Sync{
		Container: container,
		Local:     sym,
		Remote:    remote,
	})

	return nil
}
开发者ID:cleblanc87,项目名称:rack,代码行数:26,代码来源:manifest.go

示例5: ctor

func ctor(cfg *vm.Config, index int) (vm.Instance, error) {
	p := new(params)
	if err := json.Unmarshal(cfg.Params, p); err != nil {
		return nil, fmt.Errorf("failed to unmarshal local params: %v", err)
	}
	if _, err := os.Stat(p.Fuzzer); err != nil {
		return nil, fmt.Errorf("fuzzer binary '%v' does not exist: %v", p.Fuzzer, err)
	}
	if _, err := os.Stat(p.Executor); err != nil {
		return nil, fmt.Errorf("executor binary '%v' does not exist: %v", p.Executor, err)
	}

	os.MkdirAll(cfg.Workdir, 0770)

	// Disable annoying segfault dmesg messages, fuzzer is going to crash a lot.
	etrace, err := os.Open("/proc/sys/debug/exception-trace")
	if err == nil {
		etrace.Write([]byte{'0'})
		etrace.Close()
	}

	// Don't write executor core files.
	syscall.Setrlimit(syscall.RLIMIT_CORE, &syscall.Rlimit{0, 0})

	loc := &local{
		params:   *p,
		workdir:  cfg.Workdir,
		syscalls: cfg.EnabledSyscalls,
		nocover:  cfg.NoCover,
		id:       index,
		mgrPort:  cfg.ManagerPort,
	}
	return loc, nil
}
开发者ID:syjzwjj,项目名称:syzkaller,代码行数:34,代码来源:local.go

示例6: main

func main() {
	var rlim syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("获取Rlimit报错 %s", err)
		os.Exit(1)
	}
	fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)

	rlim.Max = 65535
	rlim.Cur = 65535
	//err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("设置Rlimit报错 %s", err)
		os.Exit(1)
	}
	//fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		fmt.Errorf("获取Rlimit报错 %s", err)
		os.Exit(1)
	}
	fmt.Printf("ENV RLIMIT_NOFILE : %+v\n", rlim)
}
开发者ID:kuuyee,项目名称:go-apue,代码行数:25,代码来源:getrlimit.go

示例7: main

func main() {
	lim := &syscall.Rlimit{}

	syscall.Getrlimit(syscall.RLIMIT_NOFILE, lim)
	lim.Cur = 15
	syscall.Setrlimit(syscall.RLIMIT_NOFILE, lim)
	fmt.Println(lim)
	var s []*os.File
	for i := 0; i < int(lim.Max+10); i++ {
		f, err := os.Open("/tmp/whj.txt")
		fmt.Println(f, err)
		s = append(s, f)
		err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, lim)
		fmt.Println(lim, err)
	}
	err := syscall.Getrlimit(syscall.RLIMIT_CORE, lim)
	fmt.Println(lim, err)
	rusage := &syscall.Rusage{}
	err = syscall.Getrusage(0, rusage)
	fmt.Println(rusage, err)
	err = syscall.Getrusage(1, rusage)
	fmt.Println(rusage, err)
	err = syscall.Getrusage(2, rusage)
	fmt.Println(rusage, err)
	err = syscall.Getrusage(3, rusage)
	fmt.Println(rusage, err)
	err = syscall.Getrusage(4, rusage)
	fmt.Println(rusage, err)
}
开发者ID:yc7369,项目名称:gostudy,代码行数:29,代码来源:syscalltest.go

示例8: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	os.Setenv("GOTRACEBACK", "crash")

	lim := syscall.Rlimit{}
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
	if lim.Cur < _MaxOpenfile || lim.Max < _MaxOpenfile {
		lim.Cur = _MaxOpenfile
		lim.Max = _MaxOpenfile
		syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
	}

	ln, err := net.Listen("tcp", ":1153")
	if err != nil {
		log.Fatal(err)
	}
	go TCPServer(ln, queryTypeDNS)

	ln, err = net.Listen("tcp", ":1154")
	if err != nil {
		log.Fatal(err)
	}
	go TCPServer(ln, queryTypeMYIP)

	http.HandleFunc("/myip", HTTPServerMYIP)
	http.HandleFunc("/dns", HTTPServerDNS)
	http.HandleFunc("/health", HTTPServerHealth)
	log.Fatal(http.ListenAndServe(":1053", nil))
}
开发者ID:inter-rpm,项目名称:httpdns-1,代码行数:29,代码来源:main.go

示例9: Init

func Init(logPrefix string) {
	if logPrefix != "" {
		logPrefix += " "
	}

	logPrefix += fmt.Sprintf("[%v]", os.Getpid())
	f, err := logfile.Open(*logfileName, *logFrequency, *logMaxSize, *logMaxFiles)
	if err != nil {
		panic(fmt.Sprintf("unable to open logfile %s: %v", *logfileName, err))
	}
	logger := relog.New(f, logPrefix+" ",
		log.Ldate|log.Lmicroseconds|log.Lshortfile, relog.LogNameToLogLevel(*logLevel))
	relog.SetLogger(logger)

	if *gomaxprocs != 0 {
		runtime.GOMAXPROCS(*gomaxprocs)
		relog.Info("set GOMAXPROCS = %v", *gomaxprocs)
	}

	fdLimit := &syscall.Rlimit{*maxOpenFds, *maxOpenFds}
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, fdLimit); err != nil {
		relog.Fatal("can't Setrlimit %#v: err %v", *fdLimit, err)
	} else {
		relog.Info("set max-open-fds = %v", *maxOpenFds)
	}
}
开发者ID:monadbobo,项目名称:agent_leveldb,代码行数:26,代码来源:agent_config.go

示例10: setOpenFilesLimit

// setOpenFilesLimit sets the open file limit in the kernel
// cur is the soft limit, max is the ceiling (or hard limit) for that limit
func (pm *ProcessManager) setOpenFilesLimit(cur, max uint64) error {
	var rLimit syscall.Rlimit
	// First check if the limits are already what we want
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return err
	}

	// If the current values are less than we want, set them
	if rLimit.Cur < cur || rLimit.Max < max {
		if cur > rLimit.Cur {
			rLimit.Cur = cur
		}
		if max > rLimit.Max {
			rLimit.Max = max
		}

		log.Infof("Setting open files limit (soft, hard) to (%v, %v)", rLimit.Cur, rLimit.Max)
		err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:sanmiguel,项目名称:riak-mesos,代码行数:28,代码来源:manager_linux.go

示例11: SetMaxFileDescriptors

// Set Max File Descriptor limits
//
// Background information:
//
// - SG docs
//   http://developer.couchbase.com/documentation/mobile/1.1.0/develop/guides/sync-gateway/os-level-tuning/max-file-descriptors/index.html
// - Related SG issues
//   https://github.com/couchbase/sync_gateway/issues/1083
// - Hard limit vs Soft limit
//   http://unix.stackexchange.com/questions/29577/ulimit-difference-between-hard-and-soft-limits
func SetMaxFileDescriptors(requestedSoftFDLimit uint64) (uint64, error) {

	var limits syscall.Rlimit

	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil {
		return 0, err
	}

	requiresUpdate, recommendedSoftFDLimit := getSoftFDLimit(
		requestedSoftFDLimit,
		limits,
	)

	// No call to Setrlimit required, because the requested soft limit is lower than current soft limit
	if !requiresUpdate {
		return 0, nil
	}

	// Update the soft limit (but don't bother updating the hard limit, since only root can do that,
	// and it's assumed that this process is not running as root)
	limits.Cur = recommendedSoftFDLimit
	err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limits)

	if err == nil {
		Logf("Configured process to allow %d open file descriptors", recommendedSoftFDLimit)
	}

	return recommendedSoftFDLimit, err

}
开发者ID:ethanfrey,项目名称:sync_gateway,代码行数:40,代码来源:rlimit.go

示例12: TestMain

func TestMain(m *testing.M) {
	var lim syscall.Rlimit
	syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
	lim.Cur = 1024000
	lim.Max = 1024000
	syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim)
}
开发者ID:uin57,项目名称:frontd,代码行数:7,代码来源:reuse_test.go

示例13: checkAndSetUlimit

func checkAndSetUlimit() error {
	var rLimit syscall.Rlimit
	err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return fmt.Errorf("error getting rlimit: %s", err)
	}

	ipfsFileDescNum := int64(ipfsFileDescNum)

	var setting bool
	if rLimit.Cur < ipfsFileDescNum {
		if rLimit.Max < ipfsFileDescNum {
			log.Error("adjusting max")
			rLimit.Max = ipfsFileDescNum
		}
		fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
		rLimit.Cur = ipfsFileDescNum
		setting = true
	}

	err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
	if err != nil {
		return fmt.Errorf("error setting ulimit: %s", err)
	}

	if setting {
		fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
	}

	return nil
}
开发者ID:tswindell,项目名称:go-ipfs,代码行数:31,代码来源:ulimit_freebsd.go

示例14: MaximizeOpenFileLimit

// MaximizeOpenFileLimit tries to set the resource limit RLIMIT_NOFILE (number
// of open file descriptors) to the max (hard limit), if the current (soft
// limit) is below the max. Returns the new (though possibly unchanged) limit,
// or an error if it could not be changed.
func MaximizeOpenFileLimit() (int, error) {
	// Get the current limit on number of open files.
	var lim syscall.Rlimit
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		return 0, err
	}

	// If we're already at max, there's no need to try to raise the limit.
	if lim.Cur >= lim.Max {
		return int(lim.Cur), nil
	}

	// Try to increase the limit to the max.
	oldLimit := lim.Cur
	lim.Cur = lim.Max
	if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		return int(oldLimit), err
	}

	// If the set succeeded, perform a new get to see what happened. We might
	// have gotten a value lower than the one in lim.Max, if lim.Max was
	// something that indicated "unlimited" (i.e. intmax).
	if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
		// We don't really know the correct value here since Getrlimit
		// mysteriously failed after working once... Shouldn't ever happen, I
		// think.
		return 0, err
	}

	return int(lim.Cur), nil
}
开发者ID:letiemble,项目名称:syncthing,代码行数:35,代码来源:rlimit_unix.go

示例15: RestoreLimits

func RestoreLimits(limits []*Limit) error {
	for _, v := range limits {
		if err := syscall.Setrlimit(v.Resource, v.Rlimit); err != nil {
			return err
		}
	}
	return nil
}
开发者ID:rainycape,项目名称:governator,代码行数:8,代码来源:limits.go


注:本文中的syscall.Setrlimit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。