HDTenEightyP/NetNews huggingface dataset:
From: dmb@eddore.network.com (Duane M. Butler)
Newsgroups: comp.unix.programmer
Subject: close(hFile) -- Does it write data to disk?
Date: 13 Aug 92 20:35:08 GMT
Organization: Network Systems Corporation
Originator: dmb@eddore


I have ported an application from DOS to SunOS 4.1.  The application manages
some database files and uses a transaction tracking file to protect the
database integrity in the event of failure (ie., power outage).  For every
database write operation an entry is added to the transaction file.  For this
to work properly, the transaction file must be flushed to disk after every
write.  I'm currently using the close() system call followed by open() to
flush the file.  Can I safely rely on close() to write data to disk, or is
there some other mechanism?

Many Thanks,

Duane Butler
dmb@network.com
Newsgroups: comp.unix.programmer
From: fromme@ipc1.rrzn.uni-hannover.de (Michael Fromme)
Subject: Re: real-time character input
Organization: Universit"at Hannover, Germany
X-Newsreader: Tin 1.1 PL4
Date: Thu, 20 Aug 1992 16:30:39 GMT

The problem is that the Unix tty drivers provide almost two modes of
operation: the raw and the cooked mode. The most used cooked mode
provides basic line editing possibilities as character erasion via
DEL, character entry, line redraw, echoing and so on. If your program
request characters from a tty-driver operating in cooked mode, you
have to enter a complete line before the first character gets
delivered.  But you have the possibility to coorrect types and your
program has not to take care of that.

If your tty driver operates in raw mode, it delivers every character
as it is received. Though all specials like BS, DEL, NL and CR are
received as well.

Of course, there are more modes of operation. You can tell the driver
to perform CR to NL mapping on input, NL to CRNL mapping on output
etc. This is required by most terminals.

Solutions to this problem:

	1) use the stty-command to set the tty-operation-mode in a
           shell script or via system(). Most stty's provide special
	   raw and cooked-commands like macros. If you get in a mess
	   using stty enter "^Jstty sane^J" to restore normal settings.

	2) Use the curses-library, what should exist on your system.
	   curses provides raw() and noraw(), echo() and noecho()
           calls. Remember: echoing is mostly done by the tty-driver!

	3) Use iocntl-calls to set the specific options of the tty
	   driver. This is system-specific, read the ioctl(2) man
	   page of your system.

If you plan to program a line editing routine for a non commercial
application, check the readline-library from FSF (GNU).


--
Michael Fromme               Lehrgebiet      Rechnernetze und Verteilte Systeme
fromme@rvs.uni-hannover.de                       Universit"at Hannover, Germany
fromme@rvs.uni-hannover.dbp.de                       Tel: (ger) 0511 / 762 3681
Newsgroups: comp.unix.programmer
From: bhoughto@sedona.intel.com (Blair P. Houghton)
Subject: Re: A regexp quickie
Keywords: regexp.
Organization: Intel Corp., Chandler, Arizona
Date: Fri, 14 Aug 1992 16:18:34 GMT

In article <BsyqJs.HIz@cck.coventry.ac.uk> ccx018@cch.coventry.ac.uk (Leslie Griffiths (Griff)) writes:
>Its easy to express either of these
>/^.*[ 	]*/
>and
>/[ 	][ 	]*.*[ 	][ 	]*/
>But how would one express both in a regexp.
>NOTE - I am using sed, so no full regexps, no | or +

sed is a cumulative process on a line.  Do like so:

	sed -e '/^.*[  ]*/...' -e '>/[     ][      ]*.*[   ][      ]*/...'

(where '...' is the action to be performed)

However, your second pattern doesn't do the job.  It
gets the longest string matching the pattern, which
includes all words between the first and last whitespace
characters on the line.  For instance, between these two
upcarets:^                                           ^

Come to look at it, your first pattern has the same
problem; it matches everything up to the last word on the
line.

You want to omit whitespace from the inner part of the pattern.
sed -e '/^[^ 	]*[	]*/...' -e '/[     ]*[^    ]*[     ]*/...'

				--Blair
				  "Slam-bam-RTFM..."
Xref: sparky comp.unix.programmer:4407 comp.unix.ultrix:6406 comp.unix.wizards:3672
From: wyman@atherton.com (Wyman Chong)
Newsgroups: comp.unix.programmer,comp.unix.ultrix,comp.unix.wizards
Subject: Duplicate pids
Keywords: vfork pid
Date: 22 Aug 92 02:29:48 GMT
Followup-To: poster
Organization: Atherton Technology, Inc.


We have been having some problem on some process management code. It is 
pretty much similar to what system(3) does. Can the kernel return duplicate
pids. We were able to get a small test program to reproduce the problem.
This happens on Sun OS 4.1.{1,2} on either Sun 3, Sparc 2's and MP's. It also
happens on Ultrix running 4.2. It does not happen on IBM's AIX 3.2. 
Is this a known BSD feature? or are we doing something wrong?

Just compile the program and run with 30000 as an argument.

pepper:wyman{6}:a.out 30000
duplicate pid found: 3227
do a "ps aux | grep 3227" to see if this is true, then hit '<CR>' to end


When you get the prompt then go to another window and do the ps command as
instructed...

pepper:wyman{13}:ps aux | grep 3227
4:wyman     3331 15.4  0.9   40  224 q4 S    19:19   0:00 grep -n 3227
52:wyman     3227  0.0  0.0    0    0 p0 Z    Aug  8  0:00 <defunct>
82:xrel      3227  0.0  0.0   64    0 p4 IW   Aug 10  0:36 rlogin ash

Wyman Chong
wyman@atherton.com

#include <stdio.h>
#include <sys/errno.h>
#include <sys/signal.h>

main(argc, argv)
int argc;
char **argv;
{
    int pid, loop;
    extern int errno;
    if ( argc == 2 )
        loop = atoi(*(argv+1));
    else
        loop = 10;

    for (; loop > 0; loop--)
    {
	pid = vfork();
	switch ( pid )
	{
	    case -1:
		perror("Fork failed");
		exit(-1);
	    case 0:
	    {
		int i;
		sigsetmask(0);
		for ( i = 0; i < 1000; i++)
		   ;
		_exit(0);
	    }
	    default:
		;
	}

	/**
	* To see if the pid is unique.
	*/
	errno = 0;
	kill(pid, 0);
		
	if ( errno != 0 && errno != ESRCH )
	{
	    char ch;

	    fprintf(stderr, "duplicate pid found: %d\n", pid);
	    fprintf(stderr, "do a \"ps aux | grep %d\" to see if this is true,",
		    pid);
	    fprintf(stderr, " then hit '<CR>' to end.\n");
	    ch = getchar();
	    exit(0);
	}

	waitpid(pid, 0, 0);
    }
    exit(0);
}
From: bsullivn@sc.sni.ie (Bryan O'Sullivan)
Newsgroups: comp.unix.programmer
Subject: Re: close(hFile) -- Does it write data to disk?
Date: 18 Aug 92 17:06:47 GMT
Article-I.D.: sc.165
Reply-To: bryan@sc.sni.ie
Organization: Siemens-Nixdorf Software Development Centre, Dublin
X-Newsreader: Tin 1.1 PL3



dmb@eddore.network.com (Duane M. Butler) writes:

: I have ported an application from DOS to SunOS 4.1.  The application manages
: some database files and uses a transaction tracking file to protect the
: database integrity in the event of failure (ie., power outage).  For every
: database write operation an entry is added to the transaction file.  For this
: to work properly, the transaction file must be flushed to disk after every
: write.  I'm currently using the close() system call followed by open() to
: flush the file.  Can I safely rely on close() to write data to disk, or is
: there some other mechanism?

Close(2) is not guaranteed to flush a file, nor is a later open(2) going
to help.  Use the fsync(2) system call; it takes a file descriptor as
its argument.

	-- Bryan

-- 
Bryan O'Sullivan                                             +353-1-767551 x225
Siemens-Nixdorf Informationssysteme AG                          bryan@sc.sni.ie
Software Development Centre                    "Theory like mist on eyeglasses.
Dublin                                          Obscure facts." -- Charlie Chan
Xref: sparky comp.unix.programmer:4404 comp.unix.misc:3334
From: bsullivn@sc.sni.ie (Bryan O'Sullivan)
Newsgroups: comp.unix.programmer,comp.unix.misc
Subject: Re: Process & Signal Question
Date: 18 Aug 92 09:42:15 GMT
Article-I.D.: sc.163
Reply-To: bryan@sc.sni.ie
Organization: Siemens-Nixdorf Software Development Centre, Dublin
X-Newsreader: Tin 1.1 PL3



obi@gumby.ocs.com (Kuryan Obi Thomas) writes:

: A vague memory tells me that on System V machines, demand-paged
: executables which are in use (being executed) can't be overwritten. If you
: could, horrid things would happen to the running process when it tried to
: demand page from the executable. I believe the errno you get if you try to
: open such an executable image for writing is ETXTBSY (Text File busy).

: Could someone confirm or deny this?

Our SVR4/386 boxen certainly allow a demand-paged executable to be
overwritten when it's in use, thus causing the executing program to
crash.  This is very annoying, but it could be just a feature of the
port of SVR4 we use.

	-- Bryan

-- 
Bryan O'Sullivan                                             +353-1-767551 x225
Siemens-Nixdorf Informationssysteme AG                          bryan@sc.sni.ie
Software Development Centre                    "Theory like mist on eyeglasses.
Dublin                                          Obscure facts." -- Charlie Chan
Newsgroups: comp.unix.programmer
From: chaiklin@cunixf.cc.columbia.edu (Seth Chaiklin)
Subject: awk question
Organization: Columbia University
Date: Sun, 16 Aug 1992 18:47:20 GMT



Where should I post an awk question?  I am trying to
understand how to work with a 2-dimensional matrix, and
can't seem to find the appropriate newsgroup.
Thanks,
Xref: sparky comp.unix.programmer:4265 comp.unix.internals:1684
From: mse@ttsi.lonestar.org (Mark Evans)
Newsgroups: comp.unix.programmer,comp.unix.internals
Subject: Re: SVR4 semaphore overhead???
Date: 13 Aug 92 02:02:03 GMT
Organization: st

In article <1992Aug8.131020.17966@ttsi.lonestar.org> I wrote:
>I have seen postings from time to time regarding the overhead of
>semaphores in SVR4, but not many followups.  I'm now in the boat
>of considering the usage of semaphores for mutual exclusion and
>resource coordination between a substantial number (~30) of 
>processes.  There is a potential for a large number of semaphores
>(60-90) to get allocated.
>
>Someone recently posted an observation that as the number of
>semaphores in a system grows, so does the overhead.  Can anyone
>confirm this?

On a Tandem Integrity R3000 machine running SVR4, I found no
degradation in performance on a given semaphore as the number of 
semaphores in a set increased from 1 to 25 (current sysgen'd max).
I am chagrined, however, at the 70 microseconds or so taken to
do a simple semop() lock, as compared to the .82 microseconds it
takes to call _test_and_set(), a mips-supplied routine in 
libc.a which performs an indivisible test-and-set (actually, it's
read-modify-write).  As suggested in previous articles and by
respondents to my original post, I am cooking up a
lightweight semaphore package using _test_and_test() for the
lock, and system semaphores (or message queue or pause/signal)
for sleep/wakeup when contention arises.

A couple of questions have come up that require expert knowledge:

(1) Is there a way for a process to reschedule itself, i.e., go to
the end of the current ready-to-run list?  I don't want to resort
to a sleep_ms() call if I can avoid it.

(2) When multiple processes contend for a system semaphore, are
they rewarded in FIFO order as the semaphore becomes available?
I have gotten the impression from previous testing that this is not so.
Can anyone explain the data structures & algorithm used behind the
scenes?

Writing this simple lock/unlock package at the user level without
resorting to priority controls is surprisingly mind-boggling if you 
consider all the races.  I'm on my fourth "I've got it" approach.
When I really do "have it," I'll happily share the results to the
many who have expressed interest in the subject.  If you think
you have a solution, I know many out here would love to see it.

Thanks

-- 
Mark S. Evans                 Tandem Telecommunications Systems Inc.
Phone: 214-516-6201           1255 W 15th St.
Fax:   214-516-6805           Plano, TX 75075
Mail:  mse@ttsi.lonestar.org
Xref: sparky comp.unix.programmer:4284 comp.unix.questions:10052
From: cherniac@bbn.com (Natasha Cherniack)
Newsgroups: comp.unix.programmer,comp.unix.questions
Subject: WANTED: Method for indexing man pages
Date: 13 Aug 92 20:49:30 GMT
Followup-To: comp.unix.programmer
Organization: BBN Systems and Technology, Inc.

Does anyone know of any software that can run on Sun workstations (3, 4) 
running SunOS that provide indexing capabilites?  In particular, I'm interested
in finding out about any existig automated mechanisms for creating reasonable 
indices from UNIX manual pages.  In the past, I have used UNIX's ptx in
conjunction with awk and yacc but I've encountered some problems when the 
things that are being indexed exceed a certain length.  Please email.

Thanks

Natasha Cherniack
cherniac@bbn.com
Newsgroups: comp.unix.programmer,comp.unix.internals
From: kworrell@tigger.cs.Colorado.EDU (Kurt Worrell)
Subject: Re: debugging streams
Keywords: n
Organization: University of Colorado, Boulder
Date: Fri, 21 Aug 1992 23:50:01 GMT

If you're not inclined to writing a streams module yourself, there
was streams tap code which was posted some time ago on one of the
source groups.  It'd probably be worthwhile to take a look at it as
a reference along with the other code posted here.

Kurt.
-- 
------------------------------------------------------------------------
Kurt Worrell				email:  kworrell@cs.colorado.edu
(303) 682-0858				usmail: 3200 Lake Park Wy # 306
(303) 682-0876					Longmont, CO 80503
Newsgroups: comp.unix.programmer
Subject: text file word counter ?
From: mccalld@vax.sonoma.edu
Date: 18 Aug 92 10:21:43 -0800
Organization: Sonoma State University

Greetings:
     Looking for a programming package which counts the number of unique
words in a file and displays the results, and also counts the number of
times each unique word appears within the file.......
Is this a programming question or hmm......
thankx
mccalld@sonoma.edu

Xref: sparky comp.unix.programmer:4316 comp.unix.misc:3236
From: bill@bailey.UUCP (Bill Glidden 882-8369)
Subject: Re: Process & Signal Question
Newsgroups: comp.unix.programmer,comp.unix.misc
Date: 15 Aug 92 05:15:54 GMT
Distribution: world
Organization: Ben Bailey's Home..Tampa Fl.

herberj@prism.CS.ORST.EDU (John Wesley Herberg) writes:
> 
> 1 - Is there an effecient way for one process to know if another is running 
> when the only thing you know about it is its name.  The way I'm doing it now
> is grabbing info for all the processes by using pstat(an HP-UX call) &
> searching through that info for a matching process name.  Is there some type 
> of call I could do on the executable to see if it is in use.  I noticed
> make doesn't allow you to update a file when its being used - how does it know?
> 
Make knows the executable is in use because when you fopen or open a file for
create and it is in use, the operating system returns an error condition to
the calling program. Of course, I don't recommend this for your situation.

> 2 - In Marc Rochkind's "Advanced Unix Programming", he says it's not a good
> idea to use the SIGUSR1/2 signals for user defined signals.  Why?  All I want 
> to do is notify another process of an event & I don't want the overhead of a
> msg, shared mem, etc.  Seems to me this would be the most effecient way.  Is
> there something else I should know about using signals?
> 
I believe the point he is trying to make (on page 211) is that a signal is
not recommended for inter-process communication, because signals have no
information content. As an event trigger, though, I think that a signal
works just fine if you are willing to code the overhead of catching and
resetting it. Also, how often will you be signalling the other process?
If it is more than once, remember to reset the signal catching function
for SIGUSR1 immediately upon entering the signal catching function.
From: patrick@themis.cs.umass.edu (Patrick Healy)
Newsgroups: comp.unix.programmer
Subject: handling SIGCHLD correctly and reusing broadcast sockets
Date: 19 Aug 92 00:06:22 GMT
Reply-To: patrick@themis.cs.umass.edu (Patrick Healy)
Organization: University of Massachusetts, Amherst



M/C: DECstation 5000; OS: Ultrix 4.2c


Two questions:

(1)  How do I correctly handle SIGCHLD signals from exiting children?
(2)  Can I use the same UDP port to both receive a broadcast and respond to
the broadcast?

Elabortions:

(1) In a server I'm building, I would like to know when a forked off process
completes so that I can check its exit status and wait() on it.  So I handle
the SIGCHLD by wait3() and check the status of each of my processes, onyl
paying attention to the processes that have exited since I last called
wait3().

My problem with this scheme is that program may be in the middle of a system
call to what Stevens calls a "slow device."  The system call (e.g, accept()) is
interrupted and I now have to deal restarting the system call etc.  Can people
tell me if there is a more elegant way of allowing me to handle the SIGCHLD
without having to go back and modify my every accept, read and write to that it
handles the interrupt in the correct way.  Right now, rather than deal with
that I have just decided to wait until a new request comes in before I wait3()
on the old one.  Thus, I always have one <exiting> process lying around.


(2)  How can I use *one* datagram socket to broadcast a message and receive a
response on the same socket?

When my client starts up, it won't know where the server currently resides.
So the first thing it does is sends out a broadcast asking that the server
make itelf known to it.  I would now like the server to reply (and send a
small amount of other configuration information) using the *same* socket.  Can
this be done?  It would seem to require setting/resetting SO_BROADCAST on the
socket, but anything more than that I can't figure out.



Answers or comments to either of these questions would be greatly appreciated.

Thanks,
Paddy Healy.

===============================================================================
Patrick Healy:	patrick@themis.cs.umass.edu
Guest of:	CS Department
Xref: sparky comp.unix.programmer:4288 comp.unix.questions:10056
From: guy@Auspex.COM (Guy Harris)
Newsgroups: comp.unix.programmer,comp.unix.questions
Subject: Re: dynamic link libraries on the sun
Date: 13 Aug 92 21:44:44 GMT
Followup-To: comp.unix.programmer
Organization: Auspex Systems, Santa Clara

>The -G option to ld combines a number of relocatable object files into a
>shared object.

Actually, as he's using SunOS 4.1.1, "ld" does that by default; there's
no "-G" flag.  SunOS 4.1.1 isn't SVR4-based.

SunOS 5.0 is based on SVR4, and does have SVR4's "-G" flag for that
purpose.
Newsgroups: comp.unix.programmer,comp.unix.internals
From: trotter@enuxhb.eas.asu.edu (Russell Trotter)
Subject: Sendmsg() on SunOS access rights
Organization: Arizona State University, Tempe
Date: Fri, 21 Aug 1992 04:31:06 GMT

Hello,

   Have any of you guys experience a wierd side effect of sendmsg()
on SunOS 4.1.2 sending access rights (socket desciptors).  I have
a program that starts a non-blocking connect on a socket, then at
a later time pass this connected socket to another process (with the
sendmsg() call).  When I step through the sendmsg() call with dbx
the struct msghdr struct gets blown away (all fields get set to zero..
including the accrights fields) and doesn't return an error ??? Does the
state of the socket have anything to do with this side effect? Thanks
to anyone who can help.

asu@panther.mot.com
trotter@enuxha.eas.asu.edu

Newsgroups: comp.unix.programmer
From: wang@saturn.sdsu.edu (Luqing Wang)
Subject: ??? about i-nodes and file system 
Organization: San Diego State University, College of Sciences
X-Newsreader: Tin 1.1 PL5
Date: Sat, 22 Aug 1992 16:30:31 GMT

Dear netters,

Right now I am worrking on a project which require to deal with a file's
disk block number directly. Is there any existing system calls which can
get a file inode structure, and the disk blocks allocated to a file?

I did this using ram i/o(treat disk as a file); First get the inode number 
of the file, then compute  the disk absolute address of the inode, then
read in the disk inode structrre. From the inode , one can easily find the 
disk block allocateion. However, this method has a deadly drawback, it
totally bypassed the unix file system, if the kernel has not write the 
recnet change of the file's inode information to disk, the program will 
get wrong infromation.

Any idea to get around this ?  Or is there a way to force the unix OS to
write all bufferd information(inodes information) to disk? I tried to use
sync from console, it does not work. Only thing I found worked so far is 
to shutdown the system, then reboot, this will force the system write most 
recent change to the disk. Obvious I can not do this in a program.

I am working SUN OS4.1

Any suggestionis highly appreciated.

Luqing



--
  .-.  ^^*^^        ;;;_         ||     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 ( o )             ~~&_/~*       ||       San Diego State University
;.   &   \     _ *___~.~.~. ^ __ ||     Internet: wang@saturn.sdsu.edu
Y/  $$$  \&/  _-_-_- _-==- ***  - +++   ||||||||||||||||||||||||||||||| 
Newsgroups: comp.unix.programmer
From: brianm@sco.com (Brian Moffet)
Subject: Re: How can a program know where it was invoked?
Organization: The Santa Cruz Operation, Inc.
Date: Fri, 14 Aug 1992 18:35:21 GMT

beowulf@titan.ucc.umass.edu (Peter Munson) writes:

>  Tacking the name of the executable onto the directory from which it
>was _invoked_ will give you garbage unless you happen to be sitting in
>the same directory as the executable.
>  The correct answer is 'no'.
>P.

Not necessarily.  Under the Unix OS, you can do an attempt at figuring
out where the binary is:

1: check to see if the argv[0] is an absolute/relative path name.
2: check to see if your psargs have any good information (may not be doable)
3: get the environment variable PATH and go through it in order
    checking to see whether the program in question exists in that directory.
4: Check to see if there is your program name in the current directory.

If you find that the file you found was actually a symbolic link,
you have to trace that link to see if it ends with a valid executable.

If all of these fail, you have a program which someone changed the name on
via execl() or something similar.  In this case, you're not going to have
much luck.

My question would be, "why would you want to know where the program is in the
first place?"  Most cases of having some startup script can be solved by
placing the startup script (or whatever) someplace sane, not where the
directory is...

brian moffet
--
"Face it, Chuck.  Taken as an aggregate, the human race is a stupid, sorry lot."
                           -- Jonathan Quist

brianm@sco.com  or uunet!sco!brianm                    Speaking for Myself
Newsgroups: comp.unix.programmer,comp.unix.,wizards
From: sullivan@cs.rose-hulman.edu (Fred Sullivan)
Subject: Re: How to restart a process after the machine is up.
Organization: Rose-Hulman Institute of Technology
Date: Mon, 17 Aug 1992 20:49:30 GMT

In article <Bt3yF9.JFI@usenet.ucs.indiana.edu> jhu@bronze.ucs.indiana.edu (Jun Hu) writes:

       I have a program which needs big amounts of CPU time. It
   has been running on the unix-based machine for a while. Because 
   the machine will be down once every month, I would like to have my 
   process terminated some way (save the core image of the process? ) 
   before the machine is down and restarted manually from the point it 
   stops after the machine is up, so the previous computing time is 
   not wasted.

A trick which may or may not be applicable.  If the current state of the 
process is easily saved (say by writing to a file) you can write a signal
handler for an unused signal (e.g. SIGUSR1), which dumps the state.

When the program starts up, have it read its starting state from the file.

When you want to shut down the machine, just send the process a signal.  I
once used this technique to keep a program running for several months.


Xref: sparky comp.unix.programmer:4259 comp.unix.questions:10012 comp.sys.sun.misc:3643