⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ulimit.def

📁 android-w.song.android.widget
💻 DEF
📖 第 1 页 / 共 2 页
字号:
This file is ulimit.def, from which is created ulimit.c.It implements the builtin "ulimit" in Bash.Copyright (C) 1987-2010 Free Software Foundation, Inc.This file is part of GNU Bash, the Bourne Again SHell.Bash is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.Bash is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Bash.  If not, see <http://www.gnu.org/licenses/>.$PRODUCES ulimit.c$BUILTIN ulimit$FUNCTION ulimit_builtin$DEPENDS_ON !_MINIX$SHORT_DOC ulimit [-SHacdefilmnpqrstuvx] [limit]Modify shell resource limits.Provides control over the resources available to the shell and processesit creates, on systems that allow such control.Options:  -S	use the `soft' resource limit  -H	use the `hard' resource limit  -a	all current limits are reported  -b	the socket buffer size  -c	the maximum size of core files created  -d	the maximum size of a process's data segment  -e	the maximum scheduling priority (`nice')  -f	the maximum size of files written by the shell and its children  -i	the maximum number of pending signals  -l	the maximum size a process may lock into memory  -m	the maximum resident set size  -n	the maximum number of open file descriptors  -p	the pipe buffer size  -q	the maximum number of bytes in POSIX message queues  -r	the maximum real-time scheduling priority  -s	the maximum stack size  -t	the maximum amount of cpu time in seconds  -u	the maximum number of user processes  -v	the size of virtual memory  -x	the maximum number of file locksIf LIMIT is given, it is the new value of the specified resource; thespecial LIMIT values `soft', `hard', and `unlimited' stand for thecurrent soft limit, the current hard limit, and no limit, respectively.Otherwise, the current value of the specified resource is printed.  Ifno option is given, then -f is assumed.Values are in 1024-byte increments, except for -t, which is in seconds,-p, which is in increments of 512 bytes, and -u, which is an unscalednumber of processes.Exit Status:Returns success unless an invalid option is supplied or an error occurs.$END#if !defined (_MINIX)#include <config.h>#include "../bashtypes.h"#ifndef _MINIX#  include <sys/param.h>#endif#if defined (HAVE_UNISTD_H)#  include <unistd.h>#endif#include <stdio.h>#include <errno.h>#include "../bashintl.h"#include "../shell.h"#include "common.h"#include "bashgetopt.h"#include "pipesize.h"#if !defined (errno)extern int errno;#endif/* For some reason, HPUX chose to make these definitions visible only if   _KERNEL is defined, so we define _KERNEL before including <sys/resource.h>   and #undef it afterward. */#if defined (HAVE_RESOURCE)#  include <sys/time.h>#  if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)#    define _KERNEL#  endif#  include <sys/resource.h>#  if defined (HPUX) && defined (RLIMIT_NEEDS_KERNEL)#    undef _KERNEL#  endif#elif defined (HAVE_SYS_TIMES_H)#  include <sys/times.h>#endif#if defined (HAVE_LIMITS_H)#  include <limits.h>#endif/* Check for the most basic symbols.  If they aren't present, this   system's <sys/resource.h> isn't very useful to us. */#if !defined (RLIMIT_FSIZE) || !defined (HAVE_GETRLIMIT)#  undef HAVE_RESOURCE#endif#if !defined (HAVE_RESOURCE) && defined (HAVE_ULIMIT_H)#  include <ulimit.h>#endif#if !defined (RLIMTYPE)#  define RLIMTYPE long#  define string_to_rlimtype(s) strtol(s, (char **)NULL, 10)#  define print_rlimtype(num, nl) printf ("%ld%s", num, nl ? "\n" : "")#endif/* Some systems use RLIMIT_NOFILE, others use RLIMIT_OFILE */#if defined (HAVE_RESOURCE) && defined (RLIMIT_OFILE) && !defined (RLIMIT_NOFILE)#  define RLIMIT_NOFILE RLIMIT_OFILE#endif /* HAVE_RESOURCE && RLIMIT_OFILE && !RLIMIT_NOFILE *//* Some systems have these, some do not. */#ifdef RLIMIT_FSIZE#  define RLIMIT_FILESIZE	RLIMIT_FSIZE#else#  define RLIMIT_FILESIZE	256#endif#define RLIMIT_PIPESIZE	257#ifdef RLIMIT_NOFILE#  define RLIMIT_OPENFILES	RLIMIT_NOFILE#else#  define RLIMIT_OPENFILES	258#endif#ifdef RLIMIT_VMEM#  define RLIMIT_VIRTMEM	RLIMIT_VMEM#  define RLIMIT_VMBLKSZ	1024#else#  ifdef RLIMIT_AS#    define RLIMIT_VIRTMEM	RLIMIT_AS#    define RLIMIT_VMBLKSZ	1024#  else#    define RLIMIT_VIRTMEM	259#    define RLIMIT_VMBLKSZ	1#  endif#endif#ifdef RLIMIT_NPROC#  define RLIMIT_MAXUPROC	RLIMIT_NPROC#else#  define RLIMIT_MAXUPROC	260#endif#if !defined (RLIM_INFINITY)#  define RLIM_INFINITY 0x7fffffff#endif#if !defined (RLIM_SAVED_CUR)#  define RLIM_SAVED_CUR RLIM_INFINITY#endif#if !defined (RLIM_SAVED_MAX)#  define RLIM_SAVED_MAX RLIM_INFINITY#endif#define LIMIT_HARD 0x01#define LIMIT_SOFT 0x02/* "Blocks" are defined as 512 bytes when in Posix mode and 1024 bytes   otherwise. */#define POSIXBLK	-2#define BLOCKSIZE(x)	(((x) == POSIXBLK) ? (posixly_correct ? 512 : 1024) : (x))extern int posixly_correct;static int _findlim __P((int));static int ulimit_internal __P((int, char *, int, int));static int get_limit __P((int, RLIMTYPE *, RLIMTYPE *));static int set_limit __P((int, RLIMTYPE, int));static void printone __P((int, RLIMTYPE, int));static void print_all_limits __P((int));static int set_all_limits __P((int, RLIMTYPE));static int filesize __P((RLIMTYPE *));static int pipesize __P((RLIMTYPE *));static int getmaxuprc __P((RLIMTYPE *));static int getmaxvm __P((RLIMTYPE *, RLIMTYPE *));typedef struct {  int  option;			/* The ulimit option for this limit. */  int  parameter;		/* Parameter to pass to get_limit (). */  int  block_factor;		/* Blocking factor for specific limit. */  const char * const description;	/* Descriptive string to output. */  const char * const units;	/* scale */} RESOURCE_LIMITS;static RESOURCE_LIMITS limits[] = {#ifdef RLIMIT_PTHREAD  { 'T',	RLIMIT_PTHREAD,  1,	"number of threads",	(char *)NULL },#endif#ifdef RLIMIT_SBSIZE  { 'b',	RLIMIT_SBSIZE,  1,	"socket buffer size",	"bytes" },#endif#ifdef RLIMIT_CORE  { 'c',	RLIMIT_CORE,  POSIXBLK,	"core file size",	"blocks" },#endif#ifdef RLIMIT_DATA  { 'd',	RLIMIT_DATA,  1024,	"data seg size",	"kbytes" },#endif#ifdef RLIMIT_NICE  { 'e',	RLIMIT_NICE,  1,	"scheduling priority",	(char *)NULL },#endif  { 'f',	RLIMIT_FILESIZE, POSIXBLK,	"file size",		"blocks" },#ifdef RLIMIT_SIGPENDING  { 'i',	RLIMIT_SIGPENDING, 1,	"pending signals",	(char *)NULL },#endif#ifdef RLIMIT_MEMLOCK  { 'l',	RLIMIT_MEMLOCK, 1024,	"max locked memory",	"kbytes" },#endif#ifdef RLIMIT_RSS  { 'm',	RLIMIT_RSS,   1024,	"max memory size",	"kbytes" },#endif /* RLIMIT_RSS */  { 'n',	RLIMIT_OPENFILES, 1,	"open files",		(char *)NULL},  { 'p',	RLIMIT_PIPESIZE, 512,	"pipe size", 		"512 bytes" },#ifdef RLIMIT_MSGQUEUE  { 'q',	RLIMIT_MSGQUEUE, 1,	"POSIX message queues",	"bytes" },#endif#ifdef RLIMIT_RTPRIO  { 'r',	RLIMIT_RTPRIO,  1,	"real-time priority",	(char *)NULL },#endif#ifdef RLIMIT_STACK  { 's',	RLIMIT_STACK, 1024,	"stack size",		"kbytes" },#endif#ifdef RLIMIT_CPU  { 't',	RLIMIT_CPU,      1,	"cpu time",		"seconds" },#endif /* RLIMIT_CPU */  { 'u',	RLIMIT_MAXUPROC, 1,	"max user processes",	(char *)NULL },#if defined (HAVE_RESOURCE)  { 'v',	RLIMIT_VIRTMEM, RLIMIT_VMBLKSZ, "virtual memory", "kbytes" },#endif#ifdef RLIMIT_SWAP  { 'w',	RLIMIT_SWAP,	1024,	"swap size",		"kbytes" },#endif#ifdef RLIMIT_LOCKS  { 'x',	RLIMIT_LOCKS,	1,	"file locks",		(char *)NULL },#endif  { -1, -1, -1, (char *)NULL, (char *)NULL }};#define NCMDS	(sizeof(limits) / sizeof(limits[0]))typedef struct _cmd {  int cmd;  char *arg;} ULCMD;static ULCMD *cmdlist;static int ncmd;static int cmdlistsz;#if !defined (HAVE_RESOURCE) && !defined (HAVE_ULIMIT)longulimit (cmd, newlim)     int cmd;     long newlim;{  errno = EINVAL;  return -1;}#endif /* !HAVE_RESOURCE && !HAVE_ULIMIT */static int_findlim (opt)     int opt;{  register int i;  for (i = 0; limits[i].option > 0; i++)    if (limits[i].option == opt)      return i;  return -1;}static char optstring[4 + 2 * NCMDS];/* Report or set limits associated with certain per-process resources.   See the help documentation in builtins.c for a full description. */intulimit_builtin (list)     register WORD_LIST *list;{  register char *s;  int c, limind, mode, opt, all_limits;  mode = 0;  all_limits = 0;  /* Idea stolen from pdksh -- build option string the first time called. */  if (optstring[0] == 0)    {      s = optstring;      *s++ = 'a'; *s++ = 'S'; *s++ = 'H';      for (c = 0; limits[c].option > 0; c++)	{	  *s++ = limits[c].option;	  *s++ = ';';	}      *s = '\0';    }  /* Initialize the command list. */  if (cmdlistsz == 0)    cmdlist = (ULCMD *)xmalloc ((cmdlistsz = 16) * sizeof (ULCMD));  ncmd = 0;  reset_internal_getopt ();  while ((opt = internal_getopt (list, optstring)) != -1)    {      switch (opt)	{	case 'a':	  all_limits++;	  break;	/* -S and -H are modifiers, not real options.  */	case 'S':	  mode |= LIMIT_SOFT;	  break;	case 'H':	  mode |= LIMIT_HARD;	  break;	case '?':	  builtin_usage ();	  return (EX_USAGE);	default:	  if (ncmd >= cmdlistsz)	    cmdlist = (ULCMD *)xrealloc (cmdlist, (cmdlistsz *= 2) * sizeof (ULCMD));	  cmdlist[ncmd].cmd = opt;	  cmdlist[ncmd++].arg = list_optarg;	  break;	}    }  list = loptend;  if (all_limits)    {#ifdef NOTYET      if (list)		/* setting */        {          if (STREQ (list->word->word, "unlimited") == 0)            {              builtin_error (_("%s: invalid limit argument"), list->word->word);              return (EXECUTION_FAILURE);            }          return (set_all_limits (mode == 0 ? LIMIT_SOFT|LIMIT_HARD : mode, RLIM_INFINITY));        }#endif      print_all_limits (mode == 0 ? LIMIT_SOFT : mode);      return (sh_chkwrite (EXECUTION_SUCCESS));    }  /* default is `ulimit -f' */  if (ncmd == 0)    {      cmdlist[ncmd].cmd = 'f';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -