Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Martin Vieregg

Pages: [1] 2 3 ... 7
1
Meanwhile, I found the programming tutorial and description of semaphores:
IBM OS/2 Warp Development Manuals, especially the document cp3.inf.

2
Yes, killing and restarting cmd.exe would work, too. I could also start with DosExecPgm and kill the process with the PID. But it is not a gentleman solution. Files could rest open (when for example copying files). The sub processes/programs cmd.exe would also get killed or can hang. Sending Ctrl-C to cmd.exe and a correct interrupt is strongly recommended. Cmd.exe always finishes a file copy when pressing Ctrl-C, for example. My program will have one limitation I cannot omit (that direct Screen IO buffer output is not supported), and this should really be the only limitation. Wim and OS4user sample programs showed us that it will be possible with a helper program of a few lines code which will have a size of 30 kB.

3
> you may see  how  a potential child ("DosSetExceptionHandler.exe")  is organized to be a  "receiver of signals"

Even if I can send an exception from the PM parent to a cmdline child, the child has to be prepared. So a helper program would be necessary nevertheless. I think I will program Wims concept, I am tired of trials... I cannot re-organize cmd.exe. Wims concept is not really compilicated. I have only to lern semaphores. The helper program will be only a few lines of code.

4
Thank you, especially Wim, Laurence and OS4USER for your comments. Now I think I will manage it without help.

Programming is like real life. I send signals to my childs, and they did not receive the messages... Make your homework now, come to dinner, go to sleep, and no response...

5
Thank you Wim for the further explanations and figures. So the "grandfather" concept should work:

Grandfather (my PM editor) starts parent (cmdhelper.exe commandline program) via DosExecPgm - synchronous or asynchronous, with own session or not makes no difference at this point, because PID is not needed. I can send basic information from the grandparent to the parent when starting the parent via commandline parameters (name of the semaphore, cmd.exe or 4os2.exe to start). (The name of the semaphore need to have a counter because perhaps several instances of my program are running, or I use WinQueryWindowProcess and use the grandfather PID for a unique semaphore name.)

The parent executes the child (cmd.exe) via DosExecPgm in asynchronous mode and remembers the PID of the child.

If a user presses Ctrl-C in the grandfather PM program, the parent cmdhelper.exe program gets informed via Semaphores.  Then the parent sends the exception to the child via DosSendSignalException.

GO.EXE will show the structure:
  cmdme.exe (PM editor)
       cmdhelper.exe
               cmd.exe

Hope this concept is OK now ? (I can start the parent in a new session, no problem, but don't understand it, because if I use the same session as in the PM program, both cmdline programs are still in the same session.)

6
Wim,
that sounds very plausible. Your description means, exceptions can only be sent from a non-PM process to a non-PM process?

If I understand the DosSendSignalException docu right, the relationship between the processes (child or not) does not matter.

Quote
DosSendSignalException sends either an XCPT_SIGNAL_INTR (Ctrl+C) or an XCPT_SIGNAL_BREAK (Ctrl+Break) signal exception to another process.
But I tried to run os4users parent and child exe from different sessions and the post does not reach the "child" anymore. So it indeed seems that a relationship is necessary.

So I could start two non-pm programs, the cmd.exe and a text-based helper exe which simply sends the message forward to cmd.exe.

Meanwhile, I have tried that both non-pm programs are childs of my PM program and are started via DosExecPgm (asynchronous to get the PID). The parent can tell the helper the PID of the brother/sister. This doesn't work, too. That means, the editor has to execute the helper and the helper has to execute cmd.exe. So my editor gets a grandparent. I'll try this and report here.

Wim, why do you think that I need to implement a new session? Cmd.exe currently runs in the same session as the parent editor.

What is a good tutorial for semaphores with OS/2 ? In my german OS/2 programmers book, semaphores are missing.

7
I think that DosStartSession is the wrong way because Sessions can include several processes and we need to get the two processes as close as possible.

It tried your sample programs and they indeed work.
The differences to my program are:

- They are running in one single cmd window. I have got a PM app (the parent editor) and a child (cmd.exe) which is not a PM program.
- I am starting DosExecPgm from a thread, your sample program has no theads.

I will now modify your parent send program to a PM app and I will see what happen.
Then I will try to execute the child from the main thread in my program.

Hope we find the reason why your program works and mine not.

8
>because new processes  are _NOT_ direct children of CmdMe

How do I have to execute cmd.exe so it gets a direct children of my program?

9
>I would like to receive a copy of MShell

Now I have fixed some other bugs and I can show the current state of the project to others. I have changed the name now to CmdMe because MShell is already occupied (a PMShell substitute for OS/2). If anyone has got a better name for the program, please tell it here.

In the attachment, you will find the current exe (version number 0.10). I have written all important stuff into the readme text file.

If we totally fail with sending exceptions to cmd.exe, I will run cmd.exe synchronously and suspend and kill the thread. This will work, but is not the preffered solution.

10
>can you give me kind of test to run on my system ?

See Reply #45. Here you can download SendException.exe. It is compiled with WDsibyl (Pascal). Meanwhile, I have compiled the EDM sample code with a C compiler, same result. The behaviour is the same like in my main program.

If SendSignalException and its relatives does not work at all, what is the purpose of these functions? Is it a bug? Does anyone has a Warp 3 (or 2.1) installation running?

We could send the exception to a different program to see if the problem is located in cmd.exe. I am not very familar with Exceptions. What does the Ctrl-C exception do in the target program? Is it like a keyboard input of Ctrl-C ? E.g. In ME Editor Ctrl-C is Page Down with Wordstar keyboard layout (Options - Settings - General). I haven't programmed receiving exceptions from outside yet.

11
>In NEPMD, it's possible to kill (and restart) the process that started CMD.EXE and it stops immediately, also visible by the CPU load.

Yes, killing and restarting will be possible (it will feel quite similar). This will be only a substitute hack if the behaviour I hope for is definitely not possible.

Another possibility is to run the child synchronous and sending the signal to the parent program PID. I tried it, but now DosSendSignalException returns 1.

>DosSendSignalException will return 205 if it receives PID other than PID of child process.
But I send the signal to the child process (81 in this case).

GO.EXE output is intersting in this case:

Code: [Select]
GO! v1.2 (Rev. 93/11/27)
(c) 1993 by Carsten Wimmer

             Parent           Num. of
Process ID Process ID Session Threads Priority Name
 Dec  Hex   Dec  Hex  Dec Hex
---------- ---------- ------- ------- -------- ---->
  51   33     0    0   21  15     1     0200   CUPSD.EXE
  46   2e     0    0   20  14     1     0200   SOCKTIDY.EXE
(...)
  32   20     1    1    1   1    30     0200     PMSHELL.EXE
  80   50    32   20   24  18     4     0200       MSHELL.EXE
  81   51    80   50   24  18     1     0200         CMD.EXE

MShell is my parent program (I will change the name later). It executes its child CMD.EXE. Nevertheless, error 205 is returned.

12
Silvan, a good idea. I compiled the simple text program SendException.exe.

Executing without parameter shows an help text:
sendexception.exe sends an exception to a PID. Enter the PID value in decimal first and the Execption type as second parameter.
Sample:  sendexception 197 2
INTR=1 BREAK=2 KILL=4


To recognize the cmd.exe session to observate, run go.exe in the cmd session you want to identify: GO 1.5
The PID we need is in the first row in the line of CMD.EXE, where GO.EXE is shown as child.

In this window, I run "dir /s" which takes a lot of time.
I tried the following input and I got:

Code: [Select]
[C:\]sendexception 106 1
DosSendSignalException returns 205

[C:\]sendexception 106 2
DosSendSignalException returns 209

[C:\]sendexception 106 4
DosSendSignalException returns 205

So the behaviour corresponds to my main program. Now the question is how to send these exceptions to cmd.exe. 209 means ERROR_INVALID_SIGNAL_NUMBER  what is completely suspect to me. 205 means ERROR_NO_SIGNAL_SENT, see the link Silvan posted above.

13
>CTRL-C works here in Larson Manager.

When pressing Ctrl-C in Larsen Commander, I get a menu with four options:
- Ctrl-C Break
- Ctrl-Break
- exit
- kill.

Ctrl-C Break and Ctrl-Break does not work, exit and kill works. My version is 1.6 milestone 3. I run C:\>  dir /s

>So why did it work for me ? I could start a session and redirect stdout and stdin without a problem.

All works fine, but only sending the Ctrl-C exception to the cmd.exe child does not work. This is the only problem.

>Perhaps your problem is that you are sending the CTRL-C to cmd.exe instead of the child process that cmd is running, make in my example?

Yes, meanwhile I have thought about this problem, too. My main program (the editor) creates a thread where cmd.exe gets executed asynchronously, that means the thread calls  DosExecPgm call and this call returns the PID which I need for sending the exception if a user in the editor presses Ctrl-C. Then the thread waits for terminating cmd.exe by using DosWaitChild. I have only one child PID. The thread which calls DosExecPgm and then waits has only a Thread ID (TID), not a PID.

So the main interest should be at the commandline window itself. The window is a PM program and inside, there is a textmode program running. Perhaps I send the exception to the wrong part ? But I have got only one PID. (Perhaps someone can explain it further what cmd.exe is.)

14
>Larson Commander seems to be able to do it.

A very interesting hint. I nearly daily use Larsen Commander. The cmd output window is indeed really interesting. It even supports marking text. I haven't checked it yet under this aspect. In opposite to my program, every command starts a new instance of cmd.exe. cmd.exe and its own PID is seen in GO and TOP. That means that it also starts DosExecPgm.
 
But - what a pity - Ctrl-C Breaks and Ctrl-Break also does not work ! Killing and exiting works. Killing ist clear, but what is exiting (while a long output is running) ? What could be the difference to killing ?This would be an option for Ctrl-C if the classic break does not work.

Anyway, searching a program which has done the job is a goodl way to find the solution.

15
Laurence also assumed that it should work, but it does not.

- I start cmd.exe via DosExecPgm without failure
- I get a valid PID which corresponds to the shown value in the TOP program
- The thread where I call DosExecPgm waits correctly with DosWaitChild
- In the main thread (user input), I call DosSendSignalException with the valid PID and XCPT_SIGNAL_INTR or XCPT_SIGNAL_BREAK
- but DosSendSignalException returns error 205 and the Exception does not reach cmd.exe.

I observe the steps with a log file.

This is the problem what is discussed the last 15 posts and noone has an idea what the problem could be. A lot of reasons for malfunction are eliminated now.

Besides this point, it seems that I have got all other problems solved and the program already works fine.

Pages: [1] 2 3 ... 7