Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <unistd.h>
- #include <syslog.h>
- #include <string.h>
- #define NTHREADS 10
- void *threadFunc(void *arg)
- {
- printf(".");
- fflush(stdout);
- // Sleep 10 seconds to give all procs a chance to start and to be bound to a cpu set
- sleep(10);
- while(1==1)
- {
- int a = 400;
- a * 400;
- a * 300;
- a / 15;
- }
- }
- int startThreads(int nthreads)
- {
- printf("Starting %d CPU threads: ", NTHREADS);
- pthread_t pta[nthreads];
- for ( int i = 0; i < nthreads; i++ )
- {
- pthread_t bla;
- pta[i] = bla;
- pthread_create(&pta[i],NULL,threadFunc,NULL);
- }
- pthread_join(pta[0],NULL);
- return 0;
- }
- int main(void)
- {
- /* Our process ID and Session ID */
- pid_t pid, sid;
- /* Fork off the parent process */
- pid = fork();
- if (pid < 0) {
- exit(EXIT_FAILURE);
- }
- /* If we got a good PID, then
- we can exit the parent process. */
- if (pid > 0) { // Child can continue to run even after the parent has finished executing
- exit(EXIT_SUCCESS);
- }
- /* Change the file mode mask */
- umask(0);
- /* Create a new SID for the child process */
- sid = setsid();
- if (sid < 0) {
- /* Log the failure */
- exit(EXIT_FAILURE);
- }
- /* Change the current working directory */
- if ((chdir("/")) < 0) {
- /* Log the failure */
- exit(EXIT_FAILURE);
- }
- startThreads(NTHREADS);
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment