trace-clone.c revision 43d1de94c304f61f20d542a031bee907cd98c2e6
1/* Ltrace Test : trace-clone.c.
2   Objectives  : Verify that ltrace can trace to child process after
3   clone called.
4
5   This file was written by Yao Qi <qiyao@cn.ibm.com>.  */
6
7#define _GNU_SOURCE
8#include <stdio.h>
9#include <sys/types.h>
10#include <stdlib.h>
11#include <sched.h>
12
13int child ()
14{
15  sleep(1);
16  return 0;
17}
18
19typedef int (* myfunc)();
20
21#define STACK_SIZE 1024
22
23int main ()
24{
25  pid_t pid;
26  static char stack[STACK_SIZE];
27#ifdef __ia64__
28  pid = __clone2((myfunc)&child, stack, STACK_SIZE, CLONE_FS, NULL);
29#else
30  pid = clone((myfunc)&child, stack + STACK_SIZE, CLONE_FS, NULL);
31#endif
32  if (pid < 0)
33    {
34      perror("clone called failed");
35      exit (1);
36    }
37
38  return 0;
39}
40