Open System Services Programmer's Guide
 fprintf(stderr,
 "sserver spawn'ed in cpu %d\n", peparm.pe_cpu);
 if ((newpid = fork()) < 0)
 {
 fprintf(stderr, "fork() failed [errno %d]\n", errno);
 exit(1);
 }
 else if (newpid == 0)
 {
 /* we are child ... spawn grandchild to avoid zombie processes */
 if (tdm_spawn(childargv[0], 0, NULL, &inherit,
 childargv, environ, &peparm, &perslt) < 0)
 {
 fprintf(stderr,
 "tdm_spawn() to cpu %d failed [errno %d]\n",
 cpuindex, errno);
 }
 exit(0); /* child goes away */
 }
 else
 {
 /* we are parent */
 wait(&newpid); /* wait for child to avoid zombie child process */
 }
 }
 }
 close(STDIN_FILENO);
 close(STDOUT_FILENO);
 cpuindex = 0;
 /* prepare fd passing message */
 fdmsghdr.msg_name = NULL;
 fdmsghdr.msg_namelen = 0;
 fdmsghdr.msg_iov = iov;
 fdmsghdr.msg_iovlen = 1;
 iov[0].iov_base = &cpuindex; /* sent but not used */
 iov[0].iov_len = sizeof(cpuindex);
 fdmsghdr.msg_control = &fdadata;
 fdmsghdr.msg_controllen = sizeof(fdadata);
 fdadata.fdcmsghdr.cmsg_len = sizeof(fdadata);
 fdadata.fdcmsghdr.cmsg_level = SOL_SOCKET;
 fdadata.fdcmsghdr.cmsg_type = SCM_RIGHTS;
 fdadata.fd = -1; /* set prior to each
 * sendmsg() call */
 /* loop until error or timeout */
 while (1)
 {
 /* initialize timeout and bitmask for select() call */
 timeval.tv_sec = IDLE_PERIOD;
 timeval.tv_usec = 0;
 FD_SET(listenfd, &fdset);
 readycount = select(listenfd+1, &fdset, NULL, NULL, &timeval);
 /* if timeout then exit */
 if (readycount == 0)
 {
 fprintf(stderr, "slaunch1 stopping - timeout\n");
 exit(0);
 }
 /* accept new connection */
 if ((fd = accept(listenfd,(struct sockaddr *)NULL,
 (size_t *)NULL)) < 0)
 {
 fprintf(stderr, "accept() call failed [errno %d]\n", errno);
 exit(1);
 }
Performance Considerations 145










