Welcome, Guest. Please login or register.

Author Topic: Exiting gracefully after created process from disk file...  (Read 2080 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Exiting gracefully after created process from disk file...
« on: June 17, 2005, 05:07:11 PM »
Hi. Can you use the task functions RemoveTask() etc. with processes ? I don't think so, so how do you exit well from a spawed(child) process created from disk then ?

What I'm trying to do would go like this: Signal the child process to prepare to finish, wich deallocates all stuff it has allocated. Then the child process enters a Wait(0L) state (safe state) waiting for something equivalent to RemoveTask() to be called in the main process. Then the main process can delete the child process (in my case UnLoadSeg it).
I'm also supposing one can't just exit() from the child process because then how can it signal the main process to UnLoadSeg it ? A easier thing would be if the child process was a function in the main program but I'm creating it from a file after a LoadSeg...
So it all boils down to how I UnLoadSeg it I guess...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Exiting gracefully after created process from disk file...
« Reply #1 on: June 17, 2005, 05:13:38 PM »
BTW, yeah I know there must be also a Forbid() Permit() pair somewhere in the main process too, to avoid currption of the Exec lists...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Exiting gracefully after CreateNewProc ()
« Reply #2 on: June 17, 2005, 05:15:01 PM »
Quote
Can you use the task functions RemoveTask() etc. with processes ?

You can RemTask() a process, but you must be very careful when you use it. It's the same for tasks too. In general it's not good design to call RemTask() for a foreign task.

Quote
I don't think so, so how do you exit well from a spawed(child) process created from disk then ?

Basically when task/process runs into final 'rts with original sp' (or end of the initial function in C), system will internally call RemTask(NULL) anyway.

In general you should avoid forcibly removing any of your child tasks/processes, if only possible. Rather you should use a signal or message to request the child to abort, then Wait() [for signal] or WaitPort() + GetMsg() [for message] in the parent to make sure the child has terminated. The child will indicate the termination by first calling Forbid(), and then Signal() [for signal] or ReplyMsg() [for message]. NOTE: There musn't be matching Permit()! The idea here is to avoid running into race condition (that is the child still executing the LoadSeg()d code while the parent already UnLoadSeg()ed it!). The child running into RemTask() will handle the missing Permit() when it removes the task/process from the system.

I know I'm beginning to sound like a broken record here, but my IPC example should demonstrate this quite well... :-)
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Exiting gracefully after CreateNewProc ()
« Reply #3 on: June 17, 2005, 05:36:16 PM »
Great! BTW the RKM Libs has a bad example then...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Exiting gracefully after CreateNewProc ()
« Reply #4 on: June 17, 2005, 05:38:07 PM »
As ever, Piru beat me to it :-D

Generally you shouldn't ever need to RemTask() - when your process completes, it is removed.

If your process runs a loop, use IPC to inform it that it's time to wrap up and go home :-)
int p; // A
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Exiting gracefully after CreateNewProc ()
« Reply #5 on: June 17, 2005, 05:39:57 PM »
Quote
BTW the RKM Libs has a bad example then...

RKMs aren't perfect. The examples often take shortcut, leave out error checking and sometimes introduce dangerous or wrong practices.

Yet, sometimes slightly bad examples are better than no examples at all... :-)

From exec.doc/RemTask autodoc:
Quote
This function removes a task from the system. Deallocation of resources should have been performed prior to calling this function.  Removing some other task is very dangerous. Generally is is best to arrange for tasks to call RemTask(0L) on themselves.

As noted before, just running into "end" of the task/process does exactly this (internally).
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show only replies by Jose
Re: Exiting gracefully after CreateNewProc ()
« Reply #6 on: June 17, 2005, 05:41:16 PM »
@Karlos

Yeah... :-D
:pint:
\\"We made Amiga, they {bleep}ed it up\\"