Re: How many i am fingered?
- From: "Prasad" <prasadjoshi124@xxxxxxxxx>
- Date: 8 Jan 2007 05:52:48 -0800
Hi Bill,
That was a gr8 solution.
I tried writing program for it but, it is failing.
[Prasad@prasadjoshi finger_count]$ cat finger_count.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main ()
{
char *file_name ;
char *home_path ;
char data[] = "No Plani re." ;
int counter = 0 ;
int fd ;
if ( ! ( home_path = getenv("HOME") ) )
{
printf ( "$HOME Not Defined.\n" ) ;
return 1 ;
}
file_name = malloc ( strlen(home_path) + strlen("/.plan") ) ;
if ( ! file_name )
{
printf ( "Unable To Assign Memory." ) ;
}
strcpy ( file_name, home_path ) ;
strcat ( file_name, "/.plan" ) ;
printf ( "%s\n", file_name ) ;
while ( 1 )
{
printf ( "Opening PIPE\n" ) ;
if ( (fd = open (file_name, O_WRONLY) ) < 0 )
{
perror ( "open : " ) ;
}
write ( fd, data, strlen(data) ) ;
close (fd) ;
counter ++ ;
printf ( "Counter : %d\n", counter ) ;
}
return 0 ;
}
[Prasad@prasadjoshi finger_count]$ ./a.out
/home/Prasad/.plan
Opening PIPE
<Blocked forever>
[Prasad@prasadjoshi finger_count]$ finger Prasad
Login: Prasad Name: Prasad Joshi
Directory: /home/Prasad Shell: /bin/bash
On since Wed Dec 20 15:15 (IST) on :0 (messages off)
On since Mon Jan 8 18:44 (IST) on pts/1 from :0.0
2 minutes 57 seconds idle
On since Mon Jan 8 18:29 (IST) on pts/2 from :0.0
On since Mon Jan 8 15:44 (IST) on pts/3 from :0.0
6 seconds idle
On since Mon Jan 8 18:29 (IST) on pts/4 from :0.0
4 minutes 19 seconds idle
On since Mon Jan 8 18:30 (IST) on pts/5 from :0.0
23 minutes 55 seconds idle
On since Mon Jan 8 19:11 (IST) on pts/7 from :0.0
9 minutes 28 seconds idle
No mail.
No Plan.
<<<<
it is printing NO Plan. which means .plan file is missing.
[Prasad@prasadjoshi ~]$ ls -la | grep -i .plan
prw-rw-r-- 1 Prasad Prasad 0 Jan 8 19:29 .plan
Please help........
Thanks and regards,
Prasad.
Bill Marcum wrote:
On 8 Jan 2007 03:01:13 -0800, Prasad
<prasadjoshi124@xxxxxxxxx> wrote:
man 2 stat
Hi All,
I am learning linux system programming. I have been given an assignment
which requires me to findout how many times i have been fingered. (I
need to use IPC somewhere).
One approach could be.
1. Whenever a finger command is ran on perticular user, .plan file from
the user's HOME drectory is read and is displayed on the screen. Now, I
can check the access time of the file and increment the counter (my be
stored in the shared memory). But, I am unaware of how to findout the
access time of the file. I need to write down user level C programm to
do this assignment.
Please provide some guidlines..
Is there any better approach to do this assignment?The .plan file could be a named pipe. You write a program that writes
to the pipe. The write will block until someone fingers you, then you
get the time.
--
Practically perfect people never permit sentiment to muddle their thinking.
-- Mary Poppins
.
- Follow-Ups:
- Re: How many i am fingered?
- From: Prasad
- Re: How many i am fingered?
- References:
- How many i am fingered?
- From: Prasad
- Re: How many i am fingered?
- From: Bill Marcum
- How many i am fingered?
- Prev by Date: Re: How many i am fingered?
- Next by Date: Re: How many i am fingered?
- Previous by thread: Re: How many i am fingered?
- Next by thread: Re: How many i am fingered?
- Index(es):
Relevant Pages
|