[net.unix] ulimit on Sys V

hope@gatech.CSNET (Theodore Hope) (08/23/86)

In article <12796@amdcad.UUCP> phil@amdcad.UUCP (Phil Ngai) writes:
>The 3B2 (awful) has a default file limit size of around 1 megabyte.
>Only the superuser can raise this limit with the "ulimit" command in
>sh.  (There is also a system call to change this.) The file transfer
>problem may not be in BLAST at all.

The 1-Meg ulimit problem can be fixed by changing the ulimit of the init
process to something more reasonable.  Since all processes inherit init's
ulimit, that would solve the problem.

crom@cuuxb posted the following program a few months ago.  It changes 
init's ulimit to the desired value.  On my 3b2/400 I placed it in the
/etc/brc initialization script.


--------cut here--------
/* setulimit: Written by crom@cuuxb (Michael C. Crom) 
 *
 *  This program finds init's ublock, and pokes a new ulimit into it.
 *
 */

#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/signal.h>
#include <sys/param.h>
#include <sys/dir.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/sbd.h>
#include <sys/var.h>
#include <nlist.h>

struct nlist nl[3] = {
	{ "v" },
	{ "proc" },
	{ 0 }
};
#define V_STRUCT 0
#define PROC_STRUCT 1

/* These are imposed strictly for sanity's sake */
#define MINULIMIT 1000
#define MAXULIMIT 100000
	
main(argc, argv)
int argc;
char **argv;
{
	register i;
	register fd;
	register nulimit;
	struct proc p;
	struct user u;
	struct var v;

	nulimit=atoi(argv[1]);
	if(nulimit < MINULIMIT || nulimit > MAXULIMIT)
	{
		fprintf(stderr,"Usage: %s NEWULIMIT (%d < NEWULIMIT < %d)\n",argv[0],MINULIMIT,MAXULIMIT);
		exit(1);
	}
	if(nlist("/unix", nl) == -1)
	{
		perror("Nlist on /unix failed");
		exit(1);
	}
	if((fd = open("/dev/kmem", O_RDWR)) == -1)
	{
		perror("Open of /dev/kmem failed");
		exit(2);
	}
	if((lseek(fd, nl[V_STRUCT].n_value, 0)) == -1)
	{
		perror("Lseek on v struct failed");
		exit(3);
	}
	if(read(fd, &v, sizeof(v)) != sizeof(v))
	{
		perror("Read of v struct failed");
		exit(4);
	}
	if((lseek(fd, nl[PROC_STRUCT].n_value, 0)) == -1)
	{
		perror("Lseek on proc struct failed");
		exit(3);
	}
	for(i = 0 ; i < v.v_proc ; i++)
	{
		if(read(fd, &p, sizeof(p)) != sizeof(p))
		{
			perror("Read of proc struct failed");
			exit(4);
		}
		if(p.p_pid == 1)
			break;
	}
	if(p.p_pid != 1) /* If we can't find init, we're in sad shape! */
	{
		fprintf(stderr,"Can't find init in proc table!\n");
		exit(1);
	}
	if(!(p.p_flag & SLOAD || p.p_flag & SSPART))
	{
		/* If this happens, type 'init q' to force init to be
		   swapped back in.  Then re-run this program		*/
		fprintf(stderr,"Init is swapped, can't change ulimit\n");
		exit(3);
	}
	if(lseek(fd, p.p_ubseg.wd2.address, 0) == -1)
	{
		perror("Lseek for read of init's ublock failed");
		exit(5);
	}
	if(read(fd, &u, sizeof(u)) != sizeof(u))
	{
		perror("Read of init's ublock failed");
		exit(4);
	}
	if(u.u_limit < MINULIMIT || u.u_limit > MAXULIMIT)
	{
		fprintf(stderr,"Init's ulimit currently is %d (should be > %d and < %d -- giving up!\n",u.u_limit,MINULIMIT,MAXULIMIT);
		exit(2);
	}
	printf("Old ulimit = %d\n",u.u_limit);
	printf("New ulimit = %d\n",nulimit);
	u.u_limit=nulimit;
	if(lseek(fd, p.p_ubseg.wd2.address, 0) == -1)
	{
		perror("Lseek for write of init's ublock failed");
		exit(5);
	}
	if(write(fd, &u, sizeof(u)) != sizeof(u))
	{
		perror("Write of init's ublock failed");
		exit(4);
	}
	close(fd);
}
----------cut here--------
-- 
Theodore Hope
School of Information & Computer Science, Georgia Tech, Atlanta GA 30332
CSNet:	hope@gatech		ARPA:	Hope%GATech.CSNet @ CSNet-Relay.ARPA
uucp:	...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-sally}!gatech!hope