Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Calling NT Service

Hi experts,
I got a few functions (eg. function A,B,C,D) and i would like to put these A,B,C,D functions as a one
and only one Service (or Daemon)in NT Server. This service run on the backgroud to serve many application . If application #1 call or using the service, application #2 and the rest cannot access the service....Now i don't know how to call the service from application and also don't know how to determine which application is calling the service.
Can someone give me a guide? Thanks in advance!!!:)

Regards,
Softyan Here
0
softyan
Asked:
softyan
1 Solution
 
softyanAuthor Commented:
Edited text of question
0
 
elfieCommented:
I would recommend making a deamon process  that controls all the needed functions. Once a service is requested the deamon process can spawn a child process handling the requeted function. Once the function is finished the child process notifies the deamon telling that his service is available again.

So if another is asking for the service while it's still busy, the demaon process knowns is can either give an error message back, or just blocks the call until the service is free.

I once used this technique for writing a printer deamon servicing a number of printers, connected thru special hardware interfaces, which obviously could only be used by one program at a time.
0
 
softyanAuthor Commented:
hi elfie,
   Do u have any example that can show me how to do this?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
elfieCommented:
It were drivers i wrote for my previous employer, and currently i have no useful example, unless i spend some time to it.

If you need some sample programs, the best you do is reject my answer, and ask for some sample program.

0
 
softyanAuthor Commented:
What's the different between a driver and the solution u that u proposed?
0
 
elfieCommented:
The software we wrote was part of a big project, in which we emulate a complete (out-dated) hardware (Nixdorf) On a UNIX environment.
One of the parts that we had to emulate was the printing facility that existed on the old hardware. For that we wrote a kind of spooling mechanism. But instead of what normal spooling is (request are queued but the programs who printed, can continue)
the emulation of the old hardware implied that that either the programs trying to print on a busy printer, either had to wait until sending their request, or just stop printing an retyr a bit later.

For this solution we made a deamon process (and a control file) so that we were able to see which 'printer'driver to use for which hardware device(printer). If the deamon process found that a printer driver was busy, it was returned a status back to the calling program. If the printer driver was not busy at the moment, the request was passed via the deamon process towards the printer driver. Then the program and printer driver set up their own socket connection, and teh program was able to print.
Once the printing was finished (a close operation of the printer), The printer driver send a request to the deamon telling that his service was free again.

The deamon process was listening on a global socket (defined in /etc/services). The start a printer driver, the deamon process does a 'fork', and then an exec of the correct printer driver.
The printer driver sets up a 'privat' listen queue, and send the number of 'privat' socket towards the demaon process.
If a program connects to the deamon, and the printer program is free, the deamon send the 'privat' socket number the program, which can directly connect the printer driver.

So we made a deamon process, that was controlling some (printer)drivers.


Hope this clarifies my previous comment
0
 
softyanAuthor Commented:
Thanks for helping, but since i'm using WindowsNT, i have to write a service to perform the task. I would like to know HOW the service is communicate with the application.
0
 
saneesh100Commented:
Hai..
  I think u know how to make an NT service . Then u can pass data to be communicated through any inter -processs commmunication techniques like pipe or u can use sockets etc.
 for eg in sockets it can wait for a connection and do the work so that no tohers can access it at that time and after processign it can accept  next app's request.

 I think u have got an idea .. please let me know if any clarifications needed..
0
 
softyanAuthor Commented:
Your comment is what i want, but do u have the example program that clarify the thing u said. i.e. (socket program, no others can access it at the same time). I am new to socket programming, i don't know the internal things of a socket program. I need your help to guide me through.

Thanks in advance! :)
0
 
Rajkumar_RCommented:
I think what you want is a sample program which shows how to write a NT service ! I will send you by mail. Then you can give me the points what do you think ..send me a mail if you want that sample code ! at  rajkumar.r@usa.net
0
 
softyanAuthor Commented:
I have the sample code of NT Service, but what i want is the previously comment that I said. Thanks!
0
 
ArkadiyCommented:
Why don't you try using RPC? It lets you call the function in one process and have it executed in another. It is fairly simple to use as long as you do not pass complex parameters to your functions.
0
 
softyanAuthor Commented:
Sorry, because of some other reasons, i cannot use RPC.
0
 
dwh3Commented:

Set up your program as a service. This will require you to create the program and then register it as a service with the SCM (Service Control Manager). This basically involves creating a service routine and a handler function to handle the other messages from the SCM. Your service routine will call the programs real code (what you want it to do).

How do you call the service? Your service, once running, will need to listen to requests for functions A, B, C, and D. This can be done using pipes or sockets. The service will block waiting to accept incoming requests, receive data via the chosen IPC mechanism, process the request and then block again. Any external programs will use this IPC mechanism to use the service.

How do you determine who is calling the service? In the message passed to the service which requests function A, B, C, or D simply have the client state who it is. This is just a matter of the definition for your application layer protocol.

 
0
 
nariCommented:
May be you can  use mutual exclusive mechanisms like CriticalSections (or)
mutex objects to synchronize the calls to your service.And also to determine which
application is calling the service ,you can add one more argument to your functions in
daemon process for pid(process identifier) if possible.Once you gets the call to the daemon process lock Criticalsection or mutex object and unLock them after you have done.In that way you can solve your problem
0
 
softyanAuthor Commented:
Actually, i already had the solution, but still thank those who give me the suggestion.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now