home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.unix.programmer:4330 comp.unix.misc:3253
- Newsgroups: comp.unix.programmer,comp.unix.misc
- Path: sparky!uunet!uunet.ca!geac!torag!zooid!ross
- From: Ross Ridge <ross@zooid.guild.org>
- Subject: Re: Process & Signal Question
- Organization: ZOOiD BBS
- Date: Sun, 16 Aug 1992 22:30:01 GMT
- Message-ID: <1992Aug16.223001.23257@zooid.guild.org>
- References: <1657227@bailey.UUCP>
- Lines: 54
-
- 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?
-
- bill@bailey.UUCP (Bill Glidden 882-8369) writes:
- >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.
-
- If you have write permission for the executable this should work:
-
- int fd;
-
- fd = open("foo", O_WRONLY);
- if (fd == -1)
- if (errno == ETXTBSY)
- printf("foo is running.\n");
- else
- perror("foo");
- else {
- close(fd);
- printf("foo isn't running.\n");
- }
-
-
- >>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?
-
- >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.
-
- It's possible to receive a second signal after you signal catching
- function starts but before function has a chance to reset the signal
- thus killing the process. You should use functions like sigset or
- their BSD equivilent to avoid this. Also note it's possible to lose
- signals if one arrives while another (of the same type) is pending.
-
- Ross Ridge
-
- --
- Ross Ridge - The Great HTMU l/ //
- [OO][oo]
- ross@zooid.guild.org /()\/()/
- uunet.ca!zooid!ross db //
-