How do you know that when your process forks that you are looking at the child, not the parent?

Sabyasachi Ruj wrote:
Hi,

I am writing an application which will continue to execute as a 'daemon' in
Linux.
The application is multi threaded.
And once the daemon is created, it will create few threads to perform some
tasks.

From here, I'll refer the 'process before creating the daemon' as 'PARENT
PROCESS',
and 'process after creating the daemon' as 'CHILD PROCESS'.

So the threads are being created in CHILD PROCESS.

I need to get the process id (PID) in those threads.

Here is my problem!

If I have called 'sqlite3_open' BEFORE creating the daemon,
then the PID I am getting inside the thread, is the PID of the
'PARENT PROCESS', not the 'CHILD PROCESS'!

But as after creating the daemon, the PARENT PROCESS gets killed,
those are invalid PIDs.

This happens ONLY if I am calling the 'sqlite3_open' before creating the
daemon!


I am not getting if this is the expected behavior or not.


Herewith I am attaching one sample test project, that will depict the issue.
It is having one Makefile. The executable will be named as: pidtest

To execute that process as a daemon use the '-d' command line argument.

For example:-
./pidtest -d

This process will create one log file called 'log.txt' in the current
directory.
which will show the output.

For limitation on size of the mail,I have removed SQLite source code('
sqlite3.c' and 'sqlite3.h').
I am using amalgamated code, version 3.4.0.
Checked with the latest 3.4.2. The problem is same.



------------------------------------------------------------------------

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to