473,769 Members | 5,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C vs plpgsql and child processes

Hi All,

I've written a few C functions in the version 1 format as well as some SPI
based backend bits and I'm curious as to how PG treats these items when used
within plpgsql.

The set of functions control external processes. One function is called with
various items governed by the db, does a fork and then execl to from the
child to start a new process. Whilst it's not posix i ignore the SIGCHLD
signal and let the parent process return the pid to postgres. This seems to
all be good and postgres itself obviously doesn't wait for the child to
finish (which is intentional). When the child finishes it terminates
correctly and doesn't zombie out.

Problem is that when I call these particular functions from within plpgsql
rather than through a single sql command the child never actually starts (or
starts and then exits immediately). I presume it's more to do with the fact
that what I'm doing is a bit of a hack in some senses and isn't really the
best way to go about it. Is there any specific reason why this idea wouldn't
work within plpgsql? Or should I look at moving the whole function to C? I
can certainly appreciate why it wouldn't work - just some info as to the best
way to achieve this concept would be great.

Rgds,

Jason

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #1
1 1908
Jason Godden wrote:
Hi Sean,

Yeah - It is declared VOLATILE. I think there must be something specific with
the way PL/PGSQL handles child processes of a called function. The child
process actually spawns mpg123 or ogg123 so it has to live beyond the life of
the parent. Not sure. What I might do is rewrite the entire procedure from
woe to go in using SPI and see how that goes. Failing that I guess I could
always peek at the source! : )
PL/pgSQL does not pay any attention or could affect child processes of a
backend to my knowledge. Are you sure that the PL/pgSQL function really
calls your C function forking off the child? The best way to check would
be to have some NOTICE coming out of your C function before it actually
does create the child.
Jan

Thanks,

Jason

On Mon, 18 Aug 2003 04:48 am, Sean Chittenden wrote:
> Problem is that when I call these particular functions from within
> plpgsql rather than through a single sql command the child never
> actually starts (or starts and then exits immediately).


Are you sure? I can't think of much that'd prevent a C function from
executing other than how you've declared the function (ie, is PgSQL
caching the results of the function?). Make sure you've declared it
as VOLATILE (or don't declare it anything and it'll default to
VOLATILE).

http://developer.postgresql.org/docs...efunction.html

-sc

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

--
#============== =============== =============== =============== ===========#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#============== =============== =============== ====== Ja******@Yahoo. com #
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3046
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
6
7052
by: Bob Swerdlow | last post by:
My application starts up a number of processes for various purposes using: self.popen = popen2.Popen3("/usr/local/bin/python -O "myscript.py") and then shuts them down when appropriate with os.kill(self.popen.pid, signal.SIGTERM) Everything works fine on MacOSX. However, I'm doing a port to Solaris (so I can run it on my web site) and find that the child processes are not stopping! Solaris is creating TWO new processes: one for the SHELL...
2
1582
by: Rech | last post by:
Hi, I need a little help here managing child processes in Python. I'm not so skilled in system programming so I hope you can give me some good suggestions. I have a very CPU and memory intensive task that has to be repeated many times (with different input parameters). So I've thought to write a Python script that create a child process, wait for it to finish and then starts again another child with different parameters.
0
1261
by: Wizou | last post by:
1. Create a TcpListener 2. Start a child Process 3. Kill the parent process => You can't bind to the port until you close the child process Variant : 3. Terminate normally the parent process => The parent process stays as "Running" until the child process is closed
2
3822
by: Mark Cave-Ayland | last post by:
Hi everyone, I'm trying to write a recursive plpgsql function in PostgreSQL 7.4.2 that given a tree node id (ictid) will return all the nodes below it in the tree, one row per node. When I try and execute the function I get the following error message: CONTEXT: PL/pgSQL function "findsubcategories" line 15 at for over select rows PL/pgSQL function "findsubcategories" line 15 at for over select rows
0
947
by: Stefano Bonnin | last post by:
Hi, I have a problem with plpgsql and postgres8.0.0beta2 When I execute an insert on "mytable" the psql client returns me the following: **** server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.
2
6063
by: Fred Heida | last post by:
Hi, Question on Vista Run As Administrator. If i have exe which creates a child process, using the Process class, and this exe is Run As Asministror, is there a way to have the child process also Run As Asministror with out confirmation for this (as this is already doen my the main process) ? Cheers,
22
11754
by: Jason Zheng | last post by:
This may be a silly question but is possible for os.wait() to lose track of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20 (i686), gcc4.1.1, and glibc-2.5. Here's what happened in my situation. I first created a few child processes with Popen, then in a while(True) loop wait on any of the child process to exit, then restart a child process: import os from subprocess import Popen
2
2078
by: rocco.rossi | last post by:
I'm using the Python processing module. I've just run into a problem though. Actually, it's a more general problem that isn't specific to this module, but to the handling of Unix (Linux processes) in general. Suppose for instance that for some reason or another, after forking several child processes, the main process terminates or gets killed (or segfaults or whatever) and the child processes are orphaned. Is there any way to automatically...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.