2 /* Linux-HA: pid test code
4 * Author: Jia Ming Pan <jmltc@cn.ibm.com>
5 * Modified by Guochun Shi <gshi@ncsa.uiuc.edu>
7 * Copyright (c) 2005 International Business Machines
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
29 #include <sys/types.h>
37 int grandchildflag = 0;
38 int pidconsistent = TRUE;
40 grandchild_func(void * data)
42 pid_t pid = (long) data;
45 grandchildflag = SAME;
48 if (grandchildflag ^ childflag){
49 pidconsistent = FALSE;
50 printf("Inconsistency detected\n");
56 child_func(void * data)
58 pid_t pid = (long) data;
65 pthread_create(&thread_id, NULL, grandchild_func, (void*)(long)getpid());
77 pthread_attr_init(&tattr);
78 pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
85 if (pthread_create(&thread_id, &tattr, child_func, (void*)(long)getpid()) != 0){
86 printf("%s: creating thread failed", __FUNCTION__);
99 if (waitpid(pid, &status, 0) <= 0){
100 printf("ERROR: wait for child %d failed\n",pid);
102 if (WIFEXITED(status)){
103 return (WEXITSTATUS(status));
105 printf("child process %d does not exit normally\n",pid);