[comp.os.minix] write

tholm@uvicctr.UUCP (Terrence W. Holm) (08/26/88)

EFTH MINIX report #36  - August 1988 -  write(1)


There follows an implementation of write(1) for Minix.
Please consider this public domain software.

A "man" page is included.

[Note: the first two echo's should contain a ^G.]


----------------------------------------------------------
echo x - write.1
gres '^X' '' > write.1 << '/'
XCOMMANDS
X    write(1)		- write to another user
X
XINVOCATION
X    write  ttyn
X
XEXPLANATION
X    Write(1) copies lines typed at your terminal to the
X    user signed on at device /dev/<ttyn>. When the
X    unidirectional connection is made the terminal bell
X    is sounded and the other user is notified of your
X    request by a line of the following form,
X
X	Message from user (/dev/ttym) ...
X
X    The other user can use write(1) to reply. The end of the
X    conversation is signaled by hitting the end-of-file key
X    or an INTERRUPT signal (usually DELETE).
X
X    The error message "Permission denied" means that the
X    device /dev/<ttyn> does not exist.
X
XREFERENCES
X    talk(1)
X
XPROBLEMS
X    MINIX does not support mesg(1).
/
echo x - write
gres '^X' '' > write << '/'
X#  write(1)
X
Xtrap ':' 2
X
Xif echo  2>/dev/null >/dev/$1; then
X  echo -n 
X  echo Message from `whoami` \(`tty`\) ... >/dev/$1
X  cat -u   >/dev/$1
X  echo EOT >/dev/$1
Xelse
X   echo Permission denied
Xfi
/
----------------------------------------------------------

		Edwin L. Froese
		  uw-beaver!ubc-cs!mprg!handel!froese

		Terrence W. Holm
		  uw-beaver!uvicctr!tholm

waltje@minixug.hobby.nl (Fred van Kempen) (06/29/90)

From article <1990Jun26.170818.4257@mozart.amd.com>, by tim@proton.amd.com (Tim Olson):
> In article <11355@bsu-cs.bsu.edu> jtn3@bsu-cs.bsu.edu (Jim Nelson) writes:
> | Is it permissable to use write statements in init.c?  I know that main()
> | in init.c uses them, but only inside an if statement (or while loop.  I'm
> | not looking at the source right now.) so it's never actually executed.
> | When I add them so they WILL be executed, the computer locks up (power off
> | reboot.  aargh)
> | 
> | I'm using write statements to print debugging information to the screen
> | (or I would be if they didn't cause my system to hang :-}
> 
> Init is started with no files associated with stdin, stdout, or stderr
> (FD 0, 1, and 2).  To print debug output, you must first open up a
> file (such as /dev/tty0) for each of these descriptors:
> 
> 	open("/dev/tty0", 0);	/* open descriptor 0 (stdin) for read */
> 	open("/dev/tty0", 1);	/* open descriptor 1 (stdout) for write */
> 	open("/dev/tty0", 1);	/* open descriptor 2 (stderr) for write */
> 
> 	-- Tim Olson
> 	Advanced Micro Devices
> 	(tim@amd.com)

Yeah, but then INIT will gain the Process Group Leadership for the
opened terminal device, tty0 (console) in this case.
Since this status can only be undone by exiting, INIT will ALWAYS
be the process group leader after the first open().

This means, that you cannot hit DEL on your console anymore, since
that causes a signal to be sent to the procgrp leader of the line
on which the DEL was typed, which is usually the login process
associated with a terminal device...

This bug has been around since version 1.3B of MINIX-PC...
If you really want to have INIT say something, you can do either:

1.  print(s)
    char *s;
    {
	int pid, tty;
	int status;

	if ((pid = fork()) == 0) {
		tty = open("/dev/tty0", O_WRONLY);
		if (tty < 0) exit(-1);

		write(tty, s, strlen(s));

		close(tty);
		exit(0);
	} else if (pid > 0) {
		while (wait(&status) != pid)
			    ;
	}
     }

     This routine forks a process, has it print something, and exit,
     which releases the control terminal.

2.   Use Gordon Irlam's VC driver, since that uses tty0 for the default
     console.  This is never associated with a login process, so INIT
     may use it if it pleases to.

Fred.
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| MINIX User Group Holland	  UUCP: waltje@minixug.hobby.nl |
| c/o Fred van Kempen,		    or: hp4nl!minixug!waltje    |
| Hoefbladhof  27		                  		|
| 2215 DV  VOORHOUT						|
| The Netherlands	"A good programmer knows his Sources"	|
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

schnellm@cutmcvax.OZ (schnell marcus) (07/03/90)

A small problem :

    I have a PC AT with 1M RAM. I want to keep the RAM drive Minix
    creates, but I want it located in the extended memory above 640K,
    to keep conventional memory free.

    I also want to make the RAM drive bigger; it can take all of the
    384Kb of extended memory.

    Anybody who can help ???

LOPEZM%UNAMVM1.BITNET@tecmtysb.mty.itesm.mx (Salvador Lopez Mendoza) (07/05/90)

Actually, I'm using MINIX 1.3 and the USER_GUIDE file gives information on
how to use that memory. Try to read that file.

Anyway here is the idea:

If your RAM DISK is bigger than 256K (for example 384 K) it will be loaded
outside the 640K space. Besides you can have it in a hard disk and the loading
time will be shorter.

Salvador Lopez Mendoza                       lopezm@UNAMVM1.BITNET
Facultad de Ciencias, UNAM
MEXICO