Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends ,

Could any one please let me know how we can hang a windows test service.
the purpose is to simulate some scenario.

Thanks
Sudhir
Posted

Use
while(1)
in any of the event. Your program will hang, or call recursively any function.
 
Share this answer
 
Comments
Sudhirsingh20 31-Mar-12 4:06am    
Thanks Pranit

but i wanted to know using recursive function how a particular windows nt service will hang.. could you please elaborate this...
Many thanks in advanced
Sudhirsingh20 31-Mar-12 4:09am    
I also tried with the telnet service
i attached telnet process to windbg and then try to stop the telnet service but aftersome time timeout will occur and service started..
Actually i wanted to simulate ntservices hung state STOP_PENDING/START_PENDING

Sudhir
[no name] 31-Mar-12 4:10am    
By either using while(1) or recursive function, you can put your program (so to service) to infinite loop, and it will hang your service.
Sudhirsingh20 1-Apr-12 10:12am    
Thanks very much Pranit i will try the same at my end , and let u know the results.
Neither
while (1);
nor a recursive function calls are such great ideas to let your program "hang". The "while" idea does not work well as it sends your program in a very CPU intensive loop. That sometimes makes it difficult to debug other programs at the same time.

The recursive function call will allocate more and more space to the stack and finally end by using up a lot of memory until your address space for the stack is used up. Neither such a great idea.

Why don't you simply put your thread to sleep by
while (1)
    Sleep (1000);


That will let Windows know that your thread does not want to execute for the next 1000 milliseconds and the CPU is free to do other things, like running a debugger.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900