getpid Usage

greg at perceval.be.bbs greg at perceval.be.bbs
Fri Jul 14 06:10:02 EDT 2000


In reply to the message of david at tumbleweed.com sent on Jul 13 (see below) :

You should have a look at the os.fork() function which is  python
"translation" of the fork system call (availability Unix).

It lets you create a new process (a child process) from the current one
(called the parent process). The child process execute the same than
the parent process. Thus, you have two processes, executing the same
code. The fork() function return 0 in the child process and the id
of the new created process for the parent process.

See the following example:

import os

i= os.fork()	# Create the new process

if i != 0:	# If i != 0, we are in the parent process
	print 'Forked process as the pid : ', i
else:		# We are in the child process
	os.system('ls -la')


hope-I-have-been-clear-enoughly-yours,

Gregoire Welraeds
greg at perceval.be
Perceval Development team
-------------------------------------------------------------------------------
Perceval Technologies sa/nv	Tel: +32-2-6409194
Rue Tenbosch, 9			Fax: +32-2-6403154
B-1000 Brussels			general information:   info at perceval.net
BELGIUM				technical information: helpdesk at perceval.net
URL: http://www.perceval.be/
-------------------------------------------------------------------------------

On Thu, 13 Jul 2000 david at tumbleweed.com wrote:

> Date: Thu, 13 Jul 2000 17:02:20 -0000
> From: david at tumbleweed.com
> To: python-list at cwi.nl
> Subject: getpid Usage
>
> Is there some convenient way of getting os.getpid to return the PID of
> a given executable? What I want to do is start a process and know it's
> PID. When I do the following I get the PID of the python executable.
>
> os.system("path")
> os.getpid()
>
> Alternatively, as a hack, I am doing:
> os.system(self.m_server_start_exe)
> for line in os.popen("ps -ef | grep -i IMEController | awk '{ if (NR >
> 1) { print $2 }}'").readlines():
>             pid = line[:-1]
>
> I would rather just path in an executable name/pathname and have it
> return this process' pid. Is there an updated version of os.getpid I
> could use to do this. If not, is there a better solution that is not
> shell dependent?
>
> Thanks,
> David
>
>
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
>



More information about the Python-list mailing list