🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
7 messages
7 total messages Started by superMan (the web dweller) Wed, 26 Sep 1990 15:54
Re: how to put a program into .plan file
#904
Author: superMan (the web dweller)
Date: Wed, 26 Sep 1990 15:54
30 lines
1650 bytes
In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Su
bbarao) writes:
>
>  [ some part deleted ]
>
>The "cool" way to do this is to set up your .plan as a named pipe with
>/etc/mknod.
>
>% /etc/mknod ~/.plan p (Assuming that any existing .plan is not there)
>
>Then you simply write a C program that checks the status of the file,
>to see whether someone (the fingerer) has opened it. Then simply
>write your message to the named pipe. You can do many fancy things with this.
>I know a user at our site who did something like this with his .plan, and every
>time you fingered him, it would say how many people had fingered him today,
>the weather, and even your name. And sometimes it would also finger the person
>who fingered in the first place.
>
>                               -Kartik

Pardon my ignorance, but how can you write a C program which checks the
status of the file to see whether someone has opened it?  Exactly what
system call or library function do you use?

Please send reply to Internet address achoi@cory.berkeley.edu.
Thank you so much for your reply.

Name:  Andrew Choi
Internet Address:  achoi@cory.berkeley.edu
#include <std/disclaimer.h>
Re: how to put a program into .plan file
#883
Author: Carl Edman
Date: Thu, 27 Sep 1990 01:29
59 lines
2139 bytes
In article <1990Sep26.155456.1656@agate.berkeley.edu> labb-4ac@web-4b.berkeley.edu (superMan (the web dweller)) writes:
   Pardon my ignorance, but how can you write a C program which checks the
   status of the file to see whether someone has opened it?  Exactly what
   system call or library function do you use?

   Please send reply to Internet address achoi@cory.berkeley.edu.
   Thank you so much for your reply.

   Name:  Andrew Choi
   Internet Address:  achoi@cory.berkeley.edu
   #include <std/disclaimer.h>

Here is the most simple possible solution. Something I tried a few
days ago. Run the output and try "cat tfifo". You will get 3 different
results then the run-ed program will terminate.

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

main()
   {
   int fd;
   unlink("tfifo");
   mkfifo("tfifo",S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test1\n",7);
   close(fd);
   sleep(1);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test2\n",7);
   close(fd);
   sleep(1);
   fd=open("tfifo",O_WRONLY);
   write(fd,"test3\n",7);
   close(fd);
   sleep(1);
   unlink("tfifo");
   }

I hope looking at this code will answer your question (Maybe your system
hasn't got mkfifo, use mknod then).













Theorectial Physicist,N.:A physicist whose   | Send mail
existence is postulated, to make the numbers |  to
balance but who is never actually observed   | cedman@golem.ps.uci.edu
in the laboratory.                           | edmanc@uciph0.ps.uci.edu
Re: how to put a program into .plan file
#912
Author: RANDY S WELCH
Date: Thu, 27 Sep 1990 06:02
17 lines
1283 bytes
In article <1990Sep26.155456.1656@agate.berkeley.edu> labb-4ac@web-4b.berkeley.edu (superMan (the web dweller)) writes:


   Pardon my ignorance, but how can you write a C program which checks the
   status of the file to see whether someone has opened it?  Exactly what
   system call or library function do you use?


Somewhat along the same lines, how can one tell if a file you have been
reading has been mv'ed?  

-randy
-- 
Randy Welch   Mail to :  ...!ncar!scicom!bldr!randy or rwelch@du.edu
Boulder, CO   VOICE   :  303-442-6717
"Unfortunately, life contains an unavoidable element of unpredictability"
-David Lynch "The Angriest Dog in the World"
Re: how to put a program into .plan file
#934
Author: J. S. B'ach
Date: Thu, 27 Sep 1990 12:04
21 lines
1296 bytes
In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
)
)  [ some part deleted ]
)
)The "cool" way to do this is to set up your .plan as a named pipe with
)/etc/mknod.
)
)% /etc/mknod ~/.plan p (Assuming that any existing .plan is not there)
)
)Then you simply write a C program that checks the status of the file,
)to see whether someone (the fingerer) has opened it. Then simply
)write your message to the named pipe. You can do many fancy things with this.

And does this C program run all the time checking?  Or does it sleep
until fingered?  Even in the latter case some system resources are 
permanently tied up.  Now (as Emanuel Kant might say) if everyone were
to do this, the entire process table would fill up!
-- 
    jim (rutgers!cmcl2!panix!jsb,  uunet!jyacc!jsb, or apple!panix!jsb)

    "We have no art.  We sell everything for as much as we can get."
Re: how to put a program into .plan file
#914
Author: Paul John Falstad
Date: Thu, 27 Sep 1990 13:25
13 lines
1301 bytes
In article <1990Sep27.060223.29844@mercury.cair.du.edu> rwelch@diana.cair.du.edu (RANDY S WELCH) writes:
>Somewhat along the same lines, how can one tell if a file you have been
>reading has been mv'ed?  

Couldn't you just use access() to see if it's still in the same place?
If you think someone has mv'ed your file somewhere else and then mv'ed
another one in its place, I suppose you could stat the file and fstat
your descriptor and compare the two...

If Lafontaine's elk would spurn Tom Jones, the engine must be our head, the
dining car our esophagus, the guardsvan our left lung, the kettle truck our
shins, the first class compartment the piece of skin at the nape of the neck,
and the level crossing an electric elk called Simon.
Re: how to put a program into .plan file
#927
Author: Matthew Farwell
Date: Fri, 28 Sep 1990 17:23
23 lines
1782 bytes
In article <10511@panix.UUCP> jsb@panix.UUCP (J. S. B'ach) writes:
>In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
>)Then you simply write a C program that checks the status of the file,
>)to see whether someone (the fingerer) has opened it. Then simply
>)write your message to the named pipe. You can do many fancy things with this.
>
>And does this C program run all the time checking?  Or does it sleep
>until fingered?  Even in the latter case some system resources are 
>permanently tied up.  Now (as Emanuel Kant might say) if everyone were
>to do this, the entire process table would fill up!

No. If you write on a pipe with noone at the other end, then the process
blocks (doesn't do anything), until someone starts reading from the pipe.
I had a similar version to r$'s running on this machine for about 8 hours
and it consumed 0.00 cpu seconds (according to ps). The process only takes
up cpu if someone fingers you.

Dylan.
-- 
Matthew J Farwell                 | Email: dylan@ibmpcug.co.uk
The IBM PC User Group, PO Box 360,|        ...!uunet!ukc!ibmpcug!dylan
Harrow HA1 4LQ England            | CONNECT - Usenet Access in the UK!!
Phone: +44 81-863-1191            | Sun? Don't they make coffee machines?
Re: how to put a program into .plan file
#932
Author: Paul John Falstad
Date: Fri, 28 Sep 1990 17:45
53 lines
3033 bytes
In article <10511@panix.UUCP> jsb@panix.UUCP (J. S. B'ach) writes:
>In article <2782@idunno.Princeton.EDU> subbarao@phoenix.Princeton.EDU (Kartik Subbarao) writes:
>)The "cool" way to do this is to set up your .plan as a named pipe with
>)/etc/mknod.
>)Then you simply write a C program that checks the status of the file,
>)to see whether someone (the fingerer) has opened it. Then simply
>)write your message to the named pipe. You can do many fancy things with this.
>And does this C program run all the time checking?
No.
																  Or does it sleep
>until fingered?

Yes.  It blocks until the file is opened.

					  Even in the latter case some system resources are 
>permanently tied up.  Now (as Emanuel Kant might say) if everyone were
>to do this, the entire process table would fill up!

True.  I wouldn't do this, but it is a neat hack.  This would take up
a lot of swap space and process table space.  Perhaps you could run it
just when you're logged on, and replace the named pipe with a
conventional .plan in your .logout.

Then again, someone at our site used to have a planserver that
would create a new .plan file every 5 seconds, inserting a new funny
quote each time.  This solution with the named pipes is DEFINITELY
preferable to that one, I'm sure you'll agree.

On this same subject:

In some article somewhere, Dan Bernstein writes:
>In article <2884@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes:
>> Somebody just posted an 100+ line program that does much the same thing as
>> this (unless I'm missing something really obvious):
>  [ shell script deleted ]
>> Now what am I missing??? Why does this have to be so complicated????
>Error checking, a couple of extra features, and no wasted execs. If you
>don't want to check errors, write code for Berkeley. :-)

Oh, well, of course.  I was just demonstrating the principle.  If I had
a planserver, I'd probably make it a C program.  I was just showing that
a planserver does not have to be some complicated program with select(2)
and all that.  Some error checking and the extra features could have been
added to my shell script as well.  The wasted execs are a problem,
as they would be with any shell script.

Write code for Berkeley....  Hmmm....

--
Here is the address to complain to:
pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD CIS: 70016,1355
That address again,
sync@thumper.princeton.edu PLink:OHS738 GEnie:OHS738 CIS: 4128 143 1234 937
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads