Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Apr 1999 07:05:49 -0500
From:      Zach Heilig <zach@uffdaonline.net>
To:        adrian@freebsd.org
Cc:        freebsd-current@freebsd.org
Subject:   Re: nice little kernel task for somebody
Message-ID:  <19990423070549.A78489@k6n1.znh.org>
In-Reply-To: <19990423091633.14103.qmail@ewok.creative.net.au>; from adrian@freebsd.org on Fri, Apr 23, 1999 at 05:16:33PM %2B0800
References:  <9904221732.aa19138@salmon.maths.tcd.ie> <19990423091633.14103.qmail@ewok.creative.net.au>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Apr 23, 1999 at 05:16:33PM +0800, adrian@freebsd.org wrote:
> I don't know about that one, but the first one sounds easish.
> Since I've been messing around with procfs quite a bit lately,
> I'll spend some time later today poking around and produce a patch
> against -current .

I don't know how to do this, but I did notice this much: (the binary does
remain accessible even after it's removed, as long as it doesn't exit).

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char **argv) {
  int id;
  char cmd[128];
  unlink(argv[0]);
  id = getpid();
  printf("pid == %d\n", id);
  sprintf(cmd, "ls -l /proc/%d", id);
  system(cmd);
  exit(0);
}

$ cc foo.c
$ ./a.out
pid == 78597
total 4
-r--r--r--  1 zach  wheel     0 Apr 23 07:00 cmdline
--w-------  1 zach  wheel     0 Apr 23 07:00 ctl
-r--r--r--  1 zach  wheel    76 Apr 23 07:00 etype
-rwxrwxr-x  0 zach  wheel  3637 Apr 23 07:00 file
-rw-------  1 zach  wheel   176 Apr 23 07:00 fpregs
-r--r--r--  1 zach  wheel    76 Apr 23 07:00 map
-rw-r-----  1 zach  kmem      0 Apr 23 07:00 mem
--w-------  1 zach  wheel     0 Apr 23 07:00 note
--w-------  1 zach  wheel     0 Apr 23 07:00 notepg
-rw-------  1 zach  wheel    76 Apr 23 07:00 regs
-r--r--r--  1 zach  wheel     0 Apr 23 07:00 status
$ 

[note the '0' links for the binary]

-- 
Zach Heilig <zach@uffdaonline.net>


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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