1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <errno.h>
19 #include <time.h>
20 #include <unistd.h>
21 #include "test.h"
22
23 /**
24 * @tc.name : vfork_0100
25 * @tc.desc : The parent process will execute after the child process exits, and the two share memory space
26 * @tc.level : Level 0
27 */
vfork_0100()28 void vfork_0100()
29 {
30 int a = 1;
31 int b = 2;
32
33 pid_t pid;
34 pid = vfork();
35
36 if (pid < 0) {
37 t_error("%s vfork failed\n", __func__);
38 } else if (pid == 0) {
39 sleep(1);
40 printf("child\n");
41 a = 10;
42 b = 20;
43 _exit(0);
44 } else if (pid > 0) {
45 if (a == 1 || b == 2) {
46 t_error("%s failed, a is %d, b is %d\n", __func__, a, b);
47 }
48 }
49 }
50
main(int argc,char * argv[])51 int main(int argc, char *argv[])
52 {
53 vfork_0100();
54 return t_status;
55 }