home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!ukma!wupost!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon
- From: gordon@osiris.cso.uiuc.edu (John Gordon)
- Subject: Re: A few more quick C questions...
- References: <c-r1bx#@rpi.edu>
- Message-ID: <BxrqsK.Kr4@news.cso.uiuc.edu>
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois at Urbana
- Date: Sun, 15 Nov 1992 17:48:18 GMT
- Lines: 33
-
- cecchinr@hornsby.cs.rpi.edu (Ron Cecchini) writes:
-
- >Hi again -
-
- > Thanx to everyone who responded to my read/write question of a few days ago.
-
- > I just have a couple of *quick* C questions:
-
- >1) Is there a command to see if a file exists?
- > [Can't just use fopen() - it returns NULL for more than one reason...]
-
- Try access().
-
- >2) Is there a command to determine a file's size?
- > [I think the data structure pointed to by a FILE contains a ->_cnt feild
- > that can be used - I'll try it in a minute...]
-
- Try fstat(), in particular the st_size element.
-
- >3) Is there a command to determine if a user is logged in?
- > [I don't want to bother with a system("who | grep user > temp"), etc.]
-
- Well, if you REALLY wanted to avoid the "who" route, you could
- write a program that reads the /etc/utmp file, which is supposed to
- contain a list of current users. The format is pretty weird, though.
-
- >4) Is there a command to determine if a user is running a certain process?
-
- Err....how about "ps" ?
-
- ---
- John Gordon My incredibly witty saying has been
- gordon@osiris.cso.uiuc.edu Politically Corrected into oblivion.
-