how to write a daemon

how to write a daemon

Post by hAWK » Tue, 20 Feb 2001 20:04:54



Hi all,

I want to write a daemon (or if you can suggest another way to do this) to
monitor the system for user activity.  Whenever someone logs in and runs a
job, I want to run the 'top' command and out put this to a file.  How do I
do this?  Any idea?
thanks

 
 
 

how to write a daemon

Post by David Rubi » Tue, 20 Feb 2001 17:44:08



> Hi all,

> I want to write a daemon (or if you can suggest another way to do this) to
> monitor the system for user activity.  Whenever someone logs in and runs a
> job, I want to run the 'top' command and out put this to a file.  How do I
> do this?  Any idea?
> thanks

You can poll, e.g., /var/log/wtmp, to see when users log in, but this is not
going to be accurate. Best is to attach yourself to the login code. This may
require adding code. In any case, your specification is ambiguous at best.
Several commands might be run when a user logs in. For example, a shell may be
started. Are you interested in this? How long will you allow between logging in
and running a command? Top is not going to give you much useful information
about the system unless you look at it over a period of time. Different
applications have different resource usage patters. Are you only interested in
the first command a user runs or all commands?

        david

--
FORTRAN was the language of choice
for the same reason that three-legged races are popular.
        -- Ken Thompson, "Reflections on Trusting Trust"

 
 
 

how to write a daemon

Post by Victor Wagn » Thu, 22 Feb 2001 05:47:16


: Hi all,

: I want to write a daemon (or if you can suggest another way to do this) to
: monitor the system for user activity.  Whenever someone logs in and runs a
: job, I want to run the 'top' command and out put this to a file.  How do I
: do this?  Any idea?
: thanks

On some systems, like Linux or BSD there is builtin feature in the
kernel, named ``process accounting'', which does almost what you want.
If your system have this capability, you have just turn it on
and analyze logs to find who and when used how much time for which
executables. (You'll get ``when'' with granularity of period your analyzis
script is run, but typically it is enough).

If you still want what you've described then some other hints
Use ps, not top. top is interactive program. which just runs ps with
appropriate options.

use global startup script (i.e. /etc/profile or /etc/login) for send
notification when someone logs in interactively. This wouldn't help
with user executing something like
ssh yourhost somecommand, becouse in this case there would be
non-interactive shell, but...

--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
             -- Larry Wall in the perl man page

 
 
 

1. Help:Writing Daemon Process

Could anyone direct me to articles, books, src codes on writing a simple
daemon process for Linux? Sample source code that I can ftp will be fine
too.

I run Linux Slackware 2.1 on a Quantex P90 with 540 MB harddisk
(inadequate) and 8MB RAM (barely). I use UMSDOS with Linux as a
sub-directory under DOS and I bootup from disk. Works fine so far. I
also can run X provided I swap to a 16MB file.

By the way this is my firs Linux experience.

Sincerely,

2. New Linux Conference

3. Writing a program to run as a DAEMON

4. Adjusting Shared Memory

5. How to write a daemon

6. cant create ext2 partitions on my hardisk

7. NFS daemon really sluggish when writing...

8. Backpack Bantam CDROM

9. Zombie processes and daemons under linux: need info how to write

10. When becoming a daemon, I can't write to stderr?!?!

11. How do you write a reaper (daemon)

12. Writing a daemon

13. How to write a daemon?