Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <stdio.h> /* printf */
- #include <unistd.h> /* open, read, fork */
- #include <stdlib.h> /* malloc, exit */
- #include <stdint.h> /* uint_32_t */
- #include <string.h> /* strcmp, memcpy */
- #include <pthread.h>
- #include <sched.h>
- void * pthread_func(void *arg)
- {
- printf("%s\n", __FUNCTION__);
- while(1)
- sleep(10);
- return (void *)0;
- }
- int clone_func(void *arg)
- {
- printf("%s\n", __FUNCTION__);
- while(1)
- sleep(10);
- return 0;
- }
- void fork_func(void)
- {
- if(!fork()) {
- printf("%s\n", __FUNCTION__);
- while(1)
- sleep(10);
- }
- }
- void usage(char *argv0)
- {
- printf("usage: %s [-tclf]\n", argv0);
- exit(0);
- }
- #define STACK_SIZE 4096
- int main(int argc, char *argv[])
- {
- char *stack = malloc(STACK_SIZE);
- pthread_t pt;
- if(argc != 2 || strlen(argv[1]) != 2 || argv[1][0] != '-')
- usage(argv[0]);
- switch(argv[1][1]) {
- case 't':
- pthread_create(&pt, NULL, pthread_func, 0);
- break;
- case 'c':
- clone(clone_func, stack + STACK_SIZE, 0, 0);
- break;
- case 'l':
- clone(clone_func, stack + STACK_SIZE,
- CLONE_FILES | CLONE_FS | CLONE_IO | CLONE_PARENT |
- CLONE_SIGHAND | CLONE_SYSVSEM | CLONE_THREAD | CLONE_VM, 0);
- break;
- case 'f':
- fork_func();
- break;
- default:
- usage(argv[0]);
- }
- while(1)
- sleep(10);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement