os.setpgid(pid, gid) problems

Bragi Baldursson bragi at hks.com
Tue May 29 16:51:56 EDT 2001


I have some problems with setpgid().

What I want to do is the following.  I have a gui process that uses os.popen
to run some shell scripts.   The shell scripts create other processes (they
are tarring, untarring, gzip etc).   Now if the user hits the cancel button
I want to kill all the processes.  The first shell process that I start
feeds me back its process id.  So what I wanted to do was to use that
process id and make it a group leader.  Then all processes starting from the
shell will have the same group id.  Then when I kill the process I intend to
use os.kill(-pid,9).  The minus is to kill all the children of that group
process.

The problem comes when I try to set the process group leader.  As a sample I
have created 3 shell scripts which do nothing but sleep.  I try to set the
process leader but it does not work!.  Then I finally kill the first shell
process and that works fine..........



bragi at gemini-> cat csh1
echo "This is csh1 PID = " $$
csh2&
csh3&
sleep 2
echo "Now all 3 processes are running in the background"
sleep 200

bragi at gemini-> cat csh2
echo "This is csh2 PID = " $$
sleep 200
bragi at gemini-> cat csh3
echo "This is csh3 PID = " $$
sleep 200

bragi at gemini-> python
impoPython 1.5 (#0, Oct  2 2000, 23:01:26) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os
>>> os.system("csh1&")
0
>>> This is csh1 PID =  6709
This is csh2 PID =  6712
This is csh3 PID =  6694

>>> Now all 3 processes are running in the background

>>> os.setpgid(6709,0)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
os.error: (3, 'No such process')


>>> os.setpgid(0,6709)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
os.error: (1, 'Operation not permitted')


>>> os.setpgid(6709,6709)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
os.error: (3, 'No such process')


>>> os.kill(6709,9)





More information about the Python-list mailing list