Skip to main content

[archive] Stopping System Calls From WithIn

  • December 17, 2006
  • 15 replies
  • 0 views

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,

15 replies

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
First of all, COBOL itself has no such mechanism, this is OS stuff.
C$SYSTEM will not make any difference if ran in a thread. I presume you have your reasons for why you want to run a system call, and that doing this is inevitable then.
In Windows, the "nice" way of stopping a process, is to send a message to it (WM_ENDSESSION) to make it shut down on its own. But I presume this system call of yours is running without desktop interaction? If so, there is probably no message handling either.
The only solution you have then, is to start the process using the API function CreateProcess, this will give you the process handle among a lot of other information.
With the process handle you can call the API function TerminateProcess. Note however; The function TerminateProcess is doing is exactly that, it will kill your process without questions, no matter if it is in the middle of a database update or whatever. So, besides involving CreateProcess which in itself is a bit complex, also this rough termination is something I would not recommend.
How about using the existance of a file as a metaphor? If your spawned process looked for a file someuniqenumber.terminate every 10 second or something?

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Gisle,
Thanks for responding. To give you more information on what is going on here, the application that is being spawned with the C$SYSTEM call is a custom written program that provideds 3780 communications using NDP protocal to communicate to an NCR register. This communication session is call by invoking at batch script which copies some control files, then invokes the .exe program to perform the communications. The .exe program does have screen interaction in that the user can press the escape key to terminate the session, but since the server would be running on a different PC that would probably be in a different room I need another method for terminating the process. So I think the "nice" way that you mention would probably work. I guess what I would need now is how would you determine the session id of the program? I'm assuming that I would have to get a session Id list from the system and parse it for the .exe program, then use the (WM_ENDSESSION) to terminate it. Do you have any examples of how to do this?

Thanks,

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Not a session id, but a process id. As I suggested, if you use the CreateProcess API function, you get this id. Otherwise you will have to parse the processes on the machine, checking the windowclass for each to find a match. If you are certain there will be only one such process at a time, that should be a reliable technique then.

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Ok, so far I've gotten the CreateProcess function to start a new process and I get both the Process handle and the Process ID from the Process_Information structure. The problem I'm having now is that I can't seem to get the GetExitCodeProcess function to work, so that I can check on the status of the running application. I also tried the TerminateProcess function and it would not terminate the process either. In both functions, it would return a false (0) condition, indicating that it failed. That is according to the SDK documentation. Do I need to try to set the security and access rights in order for these to work?

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
I think I figured it out, when I was calling the GetExitCodeProcess, I forgot to pass the handle as a value instead of a reference.

I changed it to:
call "GetExitCodeProcess" using
by value hProcess,
by reference lpExitCode
returning Call-R-N.

The way I was able to figure it out was by using the "GetLastError" function, it told me that it was an Invalid Handle.

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Good work!

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Well, now I'm stuck again. I've got it starting the communication process without any problems, and I can call "GetExitCodeProcess" to determine that the application is still running, but when I try to call "TerminateProcess", the server PC completely locks up to the point that nothing will work. This seems to be if the program that was called is the .exe communication process. If it is a Batch file that was called, then it will terminate with out any problems, but it only terminates the Batch file and not the exe program that was called from the batch.

Any Ideas???

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
May I see your definitions of hProcess and lpExitCode? (declaration in working storage).

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
01 Process-Information.
05 hProcess
USAGE IS HANDLE.
05 hThread
USAGE IS HANDLE.
05 dwProcessId PIC 9(5)
USAGE IS COMP-N.
05 dwThreadId PIC 9(5)
USAGE IS COMP-N.
01 lpExitCode PIC 9(5)
USAGE IS COMP-N.

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Here is probably your problem. Change all of these to PIC X(4) COMP-N.

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Here is probably your problem. Change all of these to PIC X(4) COMP-N.


Are you saying that hProcess should also be PIC X(4) COMP-N? Or just dwProcessid, dwThreadid and lpExitCode?

Thanks,

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Well, through the process of elimination, I have determined that my lockup problem is related to the application that I’m calling in using the “TerminateProcess” command. I have run the “TerminateProcess” and terminated programs like “NotePad” with no problems at all, but when I terminate this custom program, it locks up the entire PC. I put a display command right after the “TerminateProcess” call and displayed the return value and it was a 1, indicating a successful call. It’s able to display this before the computer locks up, so that makes me think it has to do with the way the program shuts down.
Unless, there is another method that I could try, I’m not going to be able to use this one.

Thanks,

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
TerminateProcess is not a clean way to kill a program (although sometimes it's the only way).

Check out this MS KB article:

http://support.microsoft.com/kb/176391

If you can be sure the program you want to kill will only have one instance running and you can predict the program's window title, you can use the FindWindow API call to get the window's handle, then send a WM_CLOSE message to it.

The article give VB code for doing it, which would need to be translated.

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Thanks Joe,
That helped, Since the program can have only one instance running at a time, it made it easy. Plus, since the program that I'm working on would be the program Creating the process, it was easy, I simply defined the process screen name and set the lpTitle to the address of that Variable. Then the
"FindWindowA" call will give me the window handle that I then used with the "EndTask" call, which did a clean shutdown of the application.

I figured that would be the direction I'd have to go, since I could re-create the lockup using the "Windows Task Manager" and using the "End Process" button on the "Processes" tab. If I did the End Task from the "Applications" screen, it would work just fine.

Thanks for everyones help,

[Migrated content. Thread originally posted on 13 December 2006]

I need to know if there is a way to stop a CALL "C$SYSTEM" command from within cobol. I'm trying to create a communications server that will call batch scripts which in turn invoke a communications program. I need to be able to stop the communications program from with in the server application, so if a user starts a long communication process, they will be able to cancel / stop it from the screen application.

The way I have the Server application set up is it has a thread that is monitoring a message que file for commands to process. When it receives a command to process from a User, it performs that process (batch file) invoking the communications process. When the comm process is complete, it then changes the status of the message record so that the user application knows that it was complete and they can continue processing. While the communications is taking place the User has a screen with a timer indicating how long it has been taking, plus a cancel button that would allow them to stop the communication process.

I haven't tried anything yet, but was thinking of using a thread to start the comm process, then I could cancel the thread, but I don't know if the "C$SYSTEM" call would work that way. BTW, this is on a Windows System.

Thanks,
Are you saying that hProcess should also be PIC X(4) COMP-N? Or just dwProcessid, dwThreadid and lpExitCode?


All of them. HANDLE is also a 4 byte unsigned and should as DWORD be created in COBOL using PIC X(4) COMP-N.