107163879Schristos /* This testcase is part of GDB, the GNU debugger.
207163879Schristos 
3*1424dfb3Schristos    Copyright 2017-2020 Free Software Foundation, Inc.
407163879Schristos 
507163879Schristos    This program is free software; you can redistribute it and/or modify
607163879Schristos    it under the terms of the GNU General Public License as published by
707163879Schristos    the Free Software Foundation; either version 3 of the License, or
807163879Schristos    (at your option) any later version.
907163879Schristos 
1007163879Schristos    This program is distributed in the hope that it will be useful,
1107163879Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1207163879Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1307163879Schristos    GNU General Public License for more details.
1407163879Schristos 
1507163879Schristos    You should have received a copy of the GNU General Public License
1607163879Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1707163879Schristos 
1807163879Schristos #include <stdlib.h>
1907163879Schristos #include <unistd.h>
2007163879Schristos 
2107163879Schristos /* GDB reads this to figure out the child's PID.  */
2207163879Schristos pid_t child_pid;
2307163879Schristos 
2407163879Schristos void
marker(void)2507163879Schristos marker (void)
2607163879Schristos {
2707163879Schristos }
2807163879Schristos 
2907163879Schristos int
main()3007163879Schristos main ()
3107163879Schristos {
3207163879Schristos   /* Don't let the test case run forever.  */
3307163879Schristos   alarm (60);
3407163879Schristos 
3507163879Schristos   child_pid = fork ();
3607163879Schristos 
3707163879Schristos   switch (child_pid)
3807163879Schristos     {
3907163879Schristos     case -1:
4007163879Schristos       return 1;
4107163879Schristos 
4207163879Schristos     case 0:
4307163879Schristos       break;
4407163879Schristos 
4507163879Schristos     default:
46*1424dfb3Schristos       /* In parent process.  */
4707163879Schristos       while (1)
4807163879Schristos 	{
4907163879Schristos 	  marker ();
5007163879Schristos 	  usleep (1000);
5107163879Schristos 	}
5207163879Schristos     }
5307163879Schristos 
54*1424dfb3Schristos   /* In child process.  */
55*1424dfb3Schristos 
56*1424dfb3Schristos   /* Alarms are not inherited by child processes. Set the alarm again to stop
57*1424dfb3Schristos      the test case running forever.  */
58*1424dfb3Schristos   alarm (60);
59*1424dfb3Schristos 
6007163879Schristos   /* Detach from controlling terminal.  */
6107163879Schristos   if (setsid () == (pid_t) -1)
6207163879Schristos     return 1;
6307163879Schristos 
64*1424dfb3Schristos   while (1)
65*1424dfb3Schristos     usleep (1000);
6607163879Schristos 
6707163879Schristos   return 0;
6807163879Schristos }
69