SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-26-2009, 01:28 PM
toricred's Avatar
toricred toricred is offline
Sage Icon
 
Join Date: Jan 2006
Location: Northern New Mexico
Posts: 1,729
Killing Fork()

I have an import with a fork() in the AfterMenuLoad area. When the menu is closed (in this case the MediaPlayer OSD) does the fork() automatically get killed or do I need to do it manually? If it's not getting killed is it possible it would cause a memory leak?
Reply With Quote
  #2  
Old 07-26-2009, 03:09 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Does the fork have a loop under it where it keeps looping? Or does it end? It is me understanding the fork simply allows a process to run in the background and allow other code/process to run in the foreground
Of course I could misunderstand but I know the fork will end once the code below is executed unless is loops somewhere
Reply With Quote
  #3  
Old 07-26-2009, 03:24 PM
toricred's Avatar
toricred toricred is offline
Sage Icon
 
Join Date: Jan 2006
Location: Northern New Mexico
Posts: 1,729
Currently there is code under it to update a panel on the OSD every minute to show the time. It doesn't have anything built-in to end it, because I was hoping that when the OSD menu was ended by ending a show it would just go away. Now I'm beginning to think I need a way to end the fork manually if the OSD is closing.

Last edited by toricred; 07-26-2009 at 04:53 PM.
Reply With Quote
  #4  
Old 07-26-2009, 05:06 PM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
A forked thread won't end automatically, especially if is in a loop, so you'll need to add some sort of check to determine whether to keep it going, or let it end. The defaul STV does quite a few forked loops in AfterMenuLoad hooks, so you could check some of them out if you need ideas about how to have it end when the menu exits.

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #5  
Old 07-26-2009, 05:59 PM
toricred's Avatar
toricred toricred is offline
Sage Icon
 
Join Date: Jan 2006
Location: Northern New Mexico
Posts: 1,729
How about a panel widget? Does it get killed when the OSD is killed? If so, I could just check to see if it still exists.
Reply With Quote
  #6  
Old 07-26-2009, 06:52 PM
toricred's Avatar
toricred toricred is offline
Sage Icon
 
Join Date: Jan 2006
Location: Northern New Mexico
Posts: 1,729
I decided to use HasMediaFile(), but I don't know how to be sure it worked. I can't tell that the fork has died in any way I can think of.
Reply With Quote
  #7  
Old 07-26-2009, 07:21 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Basically the structure of your code should be something like this:

Code:
Fork()
  ...initialize...
  If KeepLooping()
    ...do something...
    If KeepLooping()
  ...cleanup...
where the KeepLooping() function decides whether the thread should terminate or continue running. This needn't be a function; you could for instance just check an attribute variable instead, and put code in BeforeMenuUnload to set the variable to some value that tells the forked thread to quit.

To make sure it's working right, put some calls to DebugLog() in the initialize, loop body, and cleanup sections of the code so you can see the control flow.

Keeping a handle on the Panel widget won't tell you when it's been freed, since it won't be freed as long as you have a handle on it. BeforeMenuUnload is your signal that the menu is being unloaded, and it's up to you to propagate that signal to any forked threads you've created.
__________________
-- Greg
Reply With Quote
  #8  
Old 07-26-2009, 07:21 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by toricred View Post
I decided to use HasMediaFile(), but I don't know how to be sure it worked. I can't tell that the fork has died in any way I can think of.
Put a false and debug log it. If you see your message in the log then it is killed.

If HasMediaFile()

true
run your refresh or whatever you are doing

false

DebugLog("Message")
Reply With Quote
  #9  
Old 07-26-2009, 07:22 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by GKusnick View Post
propagate that signal to any forked threads you've created.
Man this was not there when I posted above
Reply With Quote
  #10  
Old 07-26-2009, 07:50 PM
toricred's Avatar
toricred toricred is offline
Sage Icon
 
Join Date: Jan 2006
Location: Northern New Mexico
Posts: 1,729
It turns out that the MC MediaPlayer Menu already has a variable being set in the BeforeMenuUnload area named forkstop. I just used that. I haven't done anything with the debugging yet, but I'll work on it later this week.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sage is killing samba server glenhein SageTV Software 2 02-14-2007 08:54 PM
Fork() Bohica SageTV Studio 3 03-25-2006 01:05 PM
IR is killing my hard drive :( bigbbri SageTV Software 27 05-08-2004 02:47 PM


All times are GMT -6. The time now is 04:23 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.