how to know how many user's connected to ftp and http server

i need to write a program to know how many users are presently connected to my ftp server and http server .
i need to keep a count of this and this count should be available to other different software . how to make this GLOBAL so that other softwares can access this count value

If it's on a UNIX system, try ps -ef |grep ftp or http (options may be different on your OS - try ps -ef). That will give you the number of connections for ftp or http normally

% ps -ef|grep -c ftp

% ps -ef|grep -c http

And please read the Rules. You posted the same question twice.

if we are talking about Apache when the amount of httpd processes doesn't correlate directly to the amount of users connected. For example, the idle apache server has some httpd processes launched already.

Slava R.

thanks for the reply , I tried the solution ,but even though there are no users connected to the ftp server it gives a value 2 and on the http server it gives a value 1.
and also i wrote the program using the given solution , i used the system("ps -ef|grep -c ftp > somefile") inside my program ,when i saw the output in the filet it had a value 3 , when no users were connected and if i used the same command on the prompt i get the value 2 how is this possible, please help me

And in the case of HTTP server there is no change like the above if no users are connected it gives the value 1

thanks for the reply , I tried the solution ,but even though there are no users connected to the ftp server it gives a value 2 and on the http server it gives a value 1.
and also i wrote the program using the given solution , i used the system("ps -ef|grep -c ftp > somefile") inside my program ,when i saw the output in the filet it had a value 3 , when no users were connected and if i used the same command on the prompt i get the value 2 how is this possible, please help me

And in the case of HTTP server there is no change like the above if no users are connected it gives the value 1

try this one to give you actual connections at the time the sample was taken ...

netstat -a | awk '/EST/ && (/ftp/ || /http/)'

Just try:

nestat -A | grep ftp

and:

grep http

this way u will c only the established connections of each one or combine them with:

nestat -A | awk '/ftp/ || /http/'

... you might want to verify the "-A" option as it seems to be OS-specific ... i don't see that option in solaris or in windows