1f08c3bdfSopenharmony_ci/* 2f08c3bdfSopenharmony_ci * Copyright (C) 2012 Cyril Hrubis <chrubis@suse.cz> 3f08c3bdfSopenharmony_ci * 4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it 5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as 6f08c3bdfSopenharmony_ci * published by the Free Software Foundation. 7f08c3bdfSopenharmony_ci * 8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but 9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Further, this software is distributed without any warranty that it is 13f08c3bdfSopenharmony_ci * free of the rightful claim of any third person regarding infringement 14f08c3bdfSopenharmony_ci * or the like. Any license provided herein, whether implied or 15f08c3bdfSopenharmony_ci * otherwise, applies only to this software file. Patent licenses, if 16f08c3bdfSopenharmony_ci * any, provided herein do not apply to combinations of this program with 17f08c3bdfSopenharmony_ci * other software, or any other product whatsoever. 18f08c3bdfSopenharmony_ci * 19f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along 20f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc., 21f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22f08c3bdfSopenharmony_ci */ 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci#include <sys/wait.h> 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci#include "test.h" 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_cichar *TCID = "tst_checkpoint_child"; 29f08c3bdfSopenharmony_ciint TST_TOTAL = 1; 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_civoid handler(int sig LTP_ATTRIBUTE_UNUSED) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci if (write(2, "Child in sighandler\n", 20)) { 34f08c3bdfSopenharmony_ci /* silence build time warnings */ 35f08c3bdfSopenharmony_ci } 36f08c3bdfSopenharmony_ci} 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ciint main(void) 39f08c3bdfSopenharmony_ci{ 40f08c3bdfSopenharmony_ci int pid; 41f08c3bdfSopenharmony_ci volatile int i; 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci pid = fork(); 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci switch (pid) { 46f08c3bdfSopenharmony_ci case -1: 47f08c3bdfSopenharmony_ci tst_brkm(TBROK | TERRNO, NULL, "Fork failed"); 48f08c3bdfSopenharmony_ci break; 49f08c3bdfSopenharmony_ci case 0: 50f08c3bdfSopenharmony_ci fprintf(stderr, "Child starts\n"); 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci signal(SIGALRM, handler); 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci for (i = 0; i < 100000000; i++); 55f08c3bdfSopenharmony_ci 56f08c3bdfSopenharmony_ci fprintf(stderr, "Child about to sleep\n"); 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_ci pause(); 59f08c3bdfSopenharmony_ci 60f08c3bdfSopenharmony_ci fprintf(stderr, "Child woken up\n"); 61f08c3bdfSopenharmony_ci 62f08c3bdfSopenharmony_ci return 0; 63f08c3bdfSopenharmony_ci break; 64f08c3bdfSopenharmony_ci default: 65f08c3bdfSopenharmony_ci /* Wait for child to sleep */ 66f08c3bdfSopenharmony_ci fprintf(stderr, "Parent waits for child to fall asleep\n"); 67f08c3bdfSopenharmony_ci TST_PROCESS_STATE_WAIT(NULL, pid, 'S'); 68f08c3bdfSopenharmony_ci fprintf(stderr, "Child sleeping, wake it\n"); 69f08c3bdfSopenharmony_ci kill(pid, SIGALRM); 70f08c3bdfSopenharmony_ci break; 71f08c3bdfSopenharmony_ci } 72f08c3bdfSopenharmony_ci 73f08c3bdfSopenharmony_ci wait(NULL); 74f08c3bdfSopenharmony_ci return 0; 75f08c3bdfSopenharmony_ci} 76