[comp.unix.questions] Becoming parent ...

MANNS%DBNPIB5.BITNET@cunyvm.cuny.edu (Jochen Manns, PI der Uni Bonn, 732738/3611) (11/03/90)

Dear UNIX-Experts,

        perhaps some of you can give me an answer of two UNIX questions:
        - is it possible for a process to become a processes parent? In
          Detail: I've got a job manager starting processes and controlling
          them especially when they die to gather statistics and so on.
          Now if the job manager dies and restarts again there no problem
          to save its internal state i.e. all the processes it started and
          recover this information from a disk file but all the children
          have got some other parents (indeed, the new parent is always
          process 1). So how can I attach to those processes again. And:
          why aren't they killed when the job manager is killed (in fact
          we like the way the did NOT die, but I would like to understand
          this)?
        - is there a way to access (argc,argv) from anywhere in a program?
          In Detail: somewhere deeply nested in a library a subroutine
          descided that it will need the commandline arguments of the
          process but there is no way to get it through the usage of
          parameters. For me it would be enough to get the whole line
          instead of (argc,argv).
        We are running UNIX V.3 on a DG AViiON 300.

Thank you in advance

                        Jochen Manns
                        Physikalisches Institut der Universitaet Bonn
                        Nussallee 12
                        5300 Bonn 1
                        (West Germany)

gwyn@smoke.brl.mil (Doug Gwyn) (11/03/90)

In article <24928@adm.BRL.MIL> MANNS%DBNPIB5.BITNET@cunyvm.cuny.edu (Jochen Manns, PI der Uni Bonn, 732738/3611) writes:
>        - is it possible for a process to become a processes parent?

I assume you mean, when the process did not start out as the other process's
parent.  The answer is, it is not supposed to happen, except for process # 1,
the "init" process, which inherits as children all processes whose original
parents terminate before they do.

>So how can I attach to those processes again.

You cannot, at least not through any means I could recommend.

>... why aren't they killed when the job manager is killed ...?

Why should they be?

UNIX allows signals to be sent to individual processes or to entire
"process groups".  Unless something is specifically attempting to signal
a process group, it will affect only one process.  If the signal is self-
generated, as for abnormal termination, only the process that generates
the signal receives it.

>        - is there a way to access (argc,argv) from anywhere in a program?

The only portable method is for the main() function to store them in some
global variables.  Some versions of UNIX do have "secret" global variables
that are set up like that by the run-time start-up module, but you cannot
rely on it across all environments.

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (11/04/90)

In article <14326@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes:
> In article <24928@adm.BRL.MIL> MANNS%DBNPIB5.BITNET@cunyvm.cuny.edu (Jochen Manns, PI der Uni Bonn, 732738/3611) writes:
> >So how can I attach to those processes again.
> You cannot, at least not through any means I could recommend.

But if he were using a BSD system, he could reattach through my pty
program. As in the following:

  % sess foo

  (then this shell dies for some reason)

  % sess reconnect xx
  (where xx is the name of the session to reattach to)

BSD wins. As usual.

---Dan

boyd@necisa.ho.necisa.oz (Boyd Roberts) (11/05/90)

In article <24928@adm.BRL.MIL> MANNS%DBNPIB5.BITNET@cunyvm.cuny.edu (Jochen Manns, PI der Uni Bonn, 732738/3611) writes:
>
>        - is it possible for a process to become a processes parent? In

No, the parent/child child relationship can only be created via fork(2).
You can't re-parent an arbitary process.  Of course, init (process 1) is
a special case.  Processes whose parent exits before them have their
parent process id change to be that of init when the parent exits.

>        - is there a way to access (argc,argv) from anywhere in a program?

Yes, declare:

    int  gargc;
    char *gargv[];

as globals and in main() go:

    main(argc, argv)
    int  argc;
    char *argv[];
    {
	gargc = argc;
	gargv = argv;

	...
    }

Isn't this one a FAQ in comp.lang.c?


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''