Re: How many i am fingered?



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:


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..

man 2 stat

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

.



Relevant Pages

  • [PATCH v3] tools: create power/x86/turbostat
    ... turbostat is a tool to help verify proper operation of CPU idle power saving ... +unsigned int skip_c0; ...
    (Linux-Kernel)
  • Re: GetIdleTime() - Help
    ... You cannot control the timeout period but the upside is that this is when the OS believes that the user is idle. ... i'm kind of new to this PDA stuff and i'm running a bit short of time.. ... I realize that the code you use is borrowed straight from the GetIdleTime ... > public static extern int GetTickCount; ...
    (microsoft.public.dotnet.framework.compactframework)
  • [cfq] sched_idle process stalled for 1 minute; strange ioprio too
    ... testing/unstable) and noticed that a massive 'apt-get upgrade' (300MB ... The machine was otherwise idle (top ... extern int sys_ioprio_set; ... ioprio = strtol; ...
    (Linux-Kernel)
  • Re: [PATCHv4 2/2] powerpc: implement arch_scale_smt_power for Power7
    ... int this_cpu, unsigned long *imbalance) ... I'm seeing check_asym_packing do the right thing with the simple SMT2 ... Do we need to give *imbalance a higher value? ... In my simple test case (SMT2, t0 idle, t1 active) if f_b_ghits our ...
    (Linux-Kernel)