[comp.sys.amiga.tech] Signaling a process

850031m@aucs.uucp (Ross MacGregor) (02/20/90)

Hello, I've been having some trouble signaling a process that Ive
CreateProc'ed.  Anybody know what Im doing wrong?

My main program seems to start the process up all right because
I can send Main a message just before the Wait() in Process.c.
Main receives this message fine.
In Main.c I do a Signal() and then WaitPort() for my debugging
message to come back to me.  It doesnt.

The process must allocate its own signal bit for its message port right?
If so this could cause an overlap of sig bits with my own.
Can you assume that this allocated bit will always be a certain one (bit 31?).
Will I have to AllocSignal() my signals and then pass these sig bits back
to Main?

Header file:

#define SIGB_KILL  31L
#define SIGB_STOP  30L
#define SIGB_START 29L

#define SIGF_KILL     (1L << SIGB_KILL)                       
#define SIGF_STOP     (1L << SIGB_STOP)                       
#define SIGF_START    (1L << SIGB_START)                      
#define SIGF_DESTPORT (1L << seq_in_dest->DestPort->mp_SigBit)

Main.c:
...
  if( (seq_port=CreatePort(SEQ_PORTNAME,10L))==NULL )
    error("Can't create port");

  if( run_proc("Process","MyProcess",&seq_in_seg,&seq_in_proc) )
    error("Can't start SeqIn");

  ...
           Signal(seq_in_proc,SIGF_START);
  ...
}

run_proc(fname,pname,seg,proc)
  char *fname,*pname;
  long *seg;
  struct Process **proc;
{
  struct WBStartup wb_msg;
  struct Process   *cur_proc;
  struct MsgPort   *reply_port;

  if( (*seg=(long)LoadSeg(fname))==NULL )
  {
    *seg=0;
    *proc=NULL;
    return 1;
  }

  if( (*proc=CreateProc(pname,5L,*seg,4000L))==NULL )
  {
    UnLoadSeg(*seg);
    *seg=0;
    *proc=NULL;
    return 2;
  }

  wb_msg.sm_Message.mn_ReplyPort=NULL;
  wb_msg.sm_Message.mn_Node.ln_Name="startup";
  wb_msg.sm_Message.mn_Length=sizeof(struct WBStartup);
  wb_msg.sm_ArgList=NULL;
  wb_msg.sm_ToolWindow=NULL;

  PutMsg(*proc,&wb_msg);

  return 0;
}

Process.c:
...
  cur_proc=(struct Process *) FindTask(0L);
  reply_port=&cur_proc->pr_MsgPort;

  seq_msg.msg.mn_ReplyPort=reply_port;
  seq_msg.msg.mn_Node.ln_Type=NT_MESSAGE;

  if( (seq_port=FindPort(SEQ_PORTNAME))==NULL)
    goto cleanup;

  AllocSignal(SIGB_KILL);
  AllocSignal(SIGB_START);
  AllocSignal(SIGB_STOP);

  while()
  {
    signals=Wait( SIGF_KILL | SIGF_START | SIGF_STOP | SIGF_DESTPORT );

/* debugging msg */
  seq_msg.type=MSG_ERRORSTAT;
  PutMsg(seq_port,&seq_msg);
  WaitPort(reply_port);
  GetMsg(reply_port);

    if( signals & SIGF_START )
      process=1;
    ...
  }
}

-- 
Ross MacGregor                                      | " Elvis Lives - I
E-mail: 850031m@AcadiaU.CA                          |   heard him on the   
UUCP:   {uunet|watmath|utai}!cs.dal.ca!aucs!850031m |   radio yesterday"