getpid/kill question

From: Joe Cipale (joec_at_aracnet.com)
Date: 05/09/04


Date: Sun, 09 May 2004 11:11:34 -0700

I have a application that spawns an xterm window using system(). I only
want the spawned window to be displayed for as long as the user is in a
certain 'location' of the application. Once they exit, then the spawned
window is to be terminated.

This lead me to use the following code snippet:
pid_t pid;

getpid = system("xterm \"Display\" -geom 80x40 &");
cout << "Var check: getpid() = " << getpid << endl;
system("kill -9 getpid");

When I exececute the system call to create the xterm and display the pid
value, the value is '0'. I then go to another window and perform:
%ps -aux | grep xterm | grep Display
 and I get a pid value that != '0'.

I would like to do this as elegantly as possible, without having to
resort to awk/sed within my code. I have the book "Advanced Programming
in the Unix Environment" by Richard Stevens, but I have not quite found
the answer to my task.

Would I be better off using something other than system() that will
generate a 'true' pid? fork() or exec*() perhaps?

TIA,

Joe

-- 
#----------------------------------------------------------#
#                "Don't fear the penguin!"                 #
#----------------------------------------------------------#
# Registered Linux user: #309247     http://counter.li.org #
#----------------------------------------------------------#


Relevant Pages

  • getpid/kill question
    ... I have a application that spawns an xterm window using system. ... want the spawned window to be displayed for as long as the user is in a ... When I exececute the system call to create the xterm and display the pid ...
    (comp.os.linux.development.apps)
  • Re: Window -> PID
    ... the X server knows the pid for each client in order to do the ... |I am familiar with the most kernel structures (actually i am digging ... |pid> and moving mouse over that window produce a massive ... no way to get it out other than via poking in the X server process ...
    (comp.unix.solaris)
  • Re: Window -> PID
    ... Is there a way I can get it somehow digging into ... the X server knows the pid for each client in order to do the ... with adb into crash files many times), ... pid> and moving mouse over that window produce a massive ...
    (comp.unix.solaris)
  • Re: OpenProcess Identify Handle
    ... a given PID, and not a hwnd If it helps, here's a snip that finds ... process PID, you can use GetWindowThreadProcessId: ... each call to OpenProcess returns a proc handle unique to the ... >Is is possible to set where a window will open using an API calls? ...
    (microsoft.public.vb.winapi)
  • Re: Fenster mit Fokus finden
    ... brauche ich die PID des Prozesses. ... static Window Select_Window; ...
    (de.comp.os.unix.x11)