2013-01-07 22:41:20 +01:00
|
|
|
/****************************************************************************
|
2021-06-10 07:51:27 +02:00
|
|
|
* apps/testing/ostest/vfork.c
|
2013-01-07 22:41:20 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-01-07 22:41:20 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-07 22:41:20 +01:00
|
|
|
*
|
2021-06-10 07:51:27 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-01-07 22:41:20 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "ostest.h"
|
|
|
|
|
2017-01-24 16:15:42 +01:00
|
|
|
#if defined(CONFIG_ARCH_HAVE_VFORK) && defined(CONFIG_SCHED_WAITPID)
|
2013-01-08 00:09:09 +01:00
|
|
|
|
2013-01-07 22:41:20 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static volatile bool g_vforkchild;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int vfork_test(void)
|
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
g_vforkchild = false;
|
|
|
|
pid = vfork();
|
|
|
|
if (pid == 0)
|
|
|
|
{
|
|
|
|
/* There is not very much that the child is permitted to do. Perhaps
|
|
|
|
* it can just set g_vforkchild.
|
|
|
|
*/
|
|
|
|
|
|
|
|
g_vforkchild = true;
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else if (pid < 0)
|
|
|
|
{
|
|
|
|
printf("vfork_test: vfork() failed: %d\n", errno);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sleep(1);
|
|
|
|
if (g_vforkchild)
|
|
|
|
{
|
|
|
|
printf("vfork_test: Child %d ran successfully\n", pid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("vfork_test: ERROR Child %d did not run\n", pid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-08 23:53:14 +01:00
|
|
|
|
2017-01-24 16:15:42 +01:00
|
|
|
#endif /* CONFIG_ARCH_HAVE_VFORK && CONFIG_SCHED_WAITPID */
|