#Forking Process

9 messages · Page 1 of 1 (latest)

leaden geode
#
    if ((pid = fork())  < 0) {
        perror("Fehler beim forken des Prozesses");
        exit(EXIT_FAILURE);
    } else if (pid == 0) {
        socket = connectToClient(config.hostname, config.portNumber);
        performHandshake(socket, gameId, spielerAnzahl);
        close(socket);
    } else {
        // implement me
    }

hi guys so i ive read abit the man page. If fork() returns 0 im in the child process and if it returns > 0 than im in the parent process (it returns the pid of the child process there)

Does the child process never know its own pid?

polar lilyBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

crisp smelt
#

!man getpid

polar lilyBOT
#

getpid, getppid - get process identification

Synopsis
#include <unistd.h>

pid_t getpid(void);
pid_t getppid(void);

crisp smelt
#

it can also use getppid to get the parent pid

leaden geode
#

oh thanks

polar lilyBOT
#

@leaden geode Has your question been resolved? If so, type !solved :)

leaden geode
#

!solved