Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Mar 1995 06:27:44 -0500
From:      starkhome!gene@sbstark.cs.sunysb.edu (Gene Stark)
To:        current@FreeBSD.org
Subject:   How to deadlock your -current system
Message-ID:  <199503071127.GAA02337@starkhome.cs.sunysb.edu>

next in thread | raw e-mail | index | archive | help
(Second posting.  I guess the first one was lost in the "freefall accident".)

Here is a fairly reliable way to cause a deadlock on my 16MB system
running -current.  I tried to make the size of the file comparable to
the size of my RAM.  I don't know if other sizes cause the same problem.

							- Gene
-------------
#include <stdio.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>

#define PSIZE 4096

main()
{
  char *name = "testfile";
  off_t max = 4000*PSIZE;
  char buf[PSIZE];
  caddr_t addr;
  int f;

  if((f = open(name, O_CREAT | O_RDWR, 0644)) < 0) {
    perror("Can't open test file");
    exit(1);
  }
  if(lseek(f, max-PSIZE, SEEK_SET) < 0) {
    perror("Seek failed");
    exit(1);
  }
  if(write(f, buf, PSIZE) < 0) {
    perror("Initial write failed");
    exit(1);
  }
  if((addr = mmap(0, max, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0))
     == NULL) {
    perror("mmap failed");
    exit(1);
  }
  while(1) {
    int r = random() % max - 1;
    *(addr + r) = 0;
  }
}




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199503071127.GAA02337>