HELP NEEDED for to get process id

HELP NEEDED for to get process id

Post by Quoc » Sat, 19 Mar 1994 11:27:17



I would like to know how to get the process id of the child
process created by fork().

My application make a fork(), and after that run an external
program via execl(), and i try to kill this external program
but I don't have its ID.

Thanks in advance  
--

    .    _  .        ____________________________
    |\_|/__/|       /                            \
   / / \/ \  \     /   Quoc Vu                    \

 |/_ \_/\_/ _\ | (                                  )  
 | | (____) | ||  \    Lab. MultiMedia (S-145)     /
 \/\___/\___/ //   \   (514)-343-6111 (ext 3494)  /
 (_/         |||    )  Universite de Montreal    /
   \        //_/ __/____________________________/
    \______//    
   __|| __||      
  (____(____)    

 
 
 

HELP NEEDED for to get process id

Post by Axel-Stephane C. Sm?rgr » Sat, 19 Mar 1994 18:47:15



> I would like to know how to get the process id of the child
> process created by fork().

> My application make a fork(), and after that run an external
> program via execl(), and i try to kill this external program
> but I don't have its ID.

> Thanks in advance  
> --

#include <sys/types.h>

uid_t  child_uid;

        child_uid = fork();

        if (child_uid == 0)
                { /* CHILD */
                  do_it();
                  exit(0);
                }
        else
        if (child_uid > 0)
                { /* PARENT */
                  printf("Child's uid is %d\n", child_uid);
                }
        else
                printf("Can't fork\n");



 
 
 

HELP NEEDED for to get process id

Post by Greg Thel » Sun, 20 Mar 1994 03:56:34


   I would like to know how to get the process id of the child
   process created by fork().

   My application make a fork(), and after that run an external
   program via execl(), and i try to kill this external program
   but I don't have its ID.

The return value of fork() is the process id of the the newly created child.

if (childPid=fork()) {
        /* Wait for child */
        /* Kill child */

Quote:} else {
        /* execl */
}      

----------------------------------
Greg Thelen
The University of Michigan
Ann Arbor, Michigan
 
 
 

HELP NEEDED for to get process id

Post by Axel-Stephane C. Sm?rgr » Wed, 23 Mar 1994 16:54:50



Quote:> #include <sys/types.h>

> uid_t  child_uid;

>    child_uid = fork();

>    if (child_uid == 0)
>            { /* CHILD */
>              do_it();
>              exit(0);
>            }
>    else
>    if (child_uid > 0)
>            { /* PARENT */
>              printf("Child's uid is %d\n", child_uid);
>            }
>    else
>            printf("Can't fork\n");

I was made aware that I used the identificator child_uid, in stead og
child_pid, which is correct correct of course. The program should have
looked like this:

 pid_t  child_pid;

        child_pid = fork();

        if (child_pid == 0)
                { /* CHILD */
                  do_it();
                  exit(0);
                }
        else
        if (child_pid > 0)
                { /* PARENT */
                  printf("Child's pid is %d\n", child_pid);
                }
        else
                printf("Can't fork\n");

As a defense for myself, I could add that my posting was written
before 11am.

-ascs