Home | History | Annotate | Line # | Download | only in kernel
h_fpufork.c revision 1.1.4.2
      1  1.1.4.2  martin /*	$NetBSD: h_fpufork.c,v 1.1.4.2 2020/04/08 14:09:08 martin Exp $	*/
      2  1.1.4.2  martin 
      3  1.1.4.2  martin /*-
      4  1.1.4.2  martin  * Copyright (c) 2020 The NetBSD Foundation, Inc.
      5  1.1.4.2  martin  * All rights reserved.
      6  1.1.4.2  martin  *
      7  1.1.4.2  martin  * Redistribution and use in source and binary forms, with or without
      8  1.1.4.2  martin  * modification, are permitted provided that the following conditions
      9  1.1.4.2  martin  * are met:
     10  1.1.4.2  martin  * 1. Redistributions of source code must retain the above copyright
     11  1.1.4.2  martin  *    notice, this list of conditions and the following disclaimer.
     12  1.1.4.2  martin  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.4.2  martin  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.4.2  martin  *    documentation and/or other materials provided with the distribution.
     15  1.1.4.2  martin  *
     16  1.1.4.2  martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1.4.2  martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1.4.2  martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1.4.2  martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1.4.2  martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1.4.2  martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1.4.2  martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1.4.2  martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1.4.2  martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1.4.2  martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1.4.2  martin  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1.4.2  martin  */
     28  1.1.4.2  martin 
     29  1.1.4.2  martin #include <sys/cdefs.h>
     30  1.1.4.2  martin __RCSID("$NetBSD: h_fpufork.c,v 1.1.4.2 2020/04/08 14:09:08 martin Exp $");
     31  1.1.4.2  martin 
     32  1.1.4.2  martin #include <sys/wait.h>
     33  1.1.4.2  martin 
     34  1.1.4.2  martin #include <err.h>
     35  1.1.4.2  martin #include <sched.h>
     36  1.1.4.2  martin #include <stdio.h>
     37  1.1.4.2  martin #include <unistd.h>
     38  1.1.4.2  martin 
     39  1.1.4.2  martin int
     40  1.1.4.2  martin main(void)
     41  1.1.4.2  martin {
     42  1.1.4.2  martin 	pid_t child, pid;
     43  1.1.4.2  martin 	volatile double x = 1;
     44  1.1.4.2  martin 	register double y = 2*x;
     45  1.1.4.2  martin 	int status;
     46  1.1.4.2  martin 
     47  1.1.4.2  martin 	pid = fork();
     48  1.1.4.2  martin 	switch (pid) {
     49  1.1.4.2  martin 	case -1:		/* error */
     50  1.1.4.2  martin 		err(1, "fork");
     51  1.1.4.2  martin 	case 0:			/* child */
     52  1.1.4.2  martin 		_exit(y == 2 ? 0 : 1);
     53  1.1.4.2  martin 	default:		/* parent */
     54  1.1.4.2  martin 		break;
     55  1.1.4.2  martin 	}
     56  1.1.4.2  martin 
     57  1.1.4.2  martin 	if ((child = wait(&status)) == -1)
     58  1.1.4.2  martin 		err(1, "wait");
     59  1.1.4.2  martin 	if (WIFSIGNALED(status))
     60  1.1.4.2  martin 		errx(1, "child exited on signal %d", WTERMSIG(status));
     61  1.1.4.2  martin 	if (!WIFEXITED(status))
     62  1.1.4.2  martin 		errx(1, "child didn't exit");
     63  1.1.4.2  martin 	return WEXITSTATUS(status);
     64  1.1.4.2  martin }
     65