Like Tree1Likes
  • 1 Post By Salem

count processes

This is a discussion on count processes within the Linux Programming forums, part of the Platform Specific Boards category; hi, it is only an exercise, how many processes are there in 30 seconds? I think 30x9 processes? It is ...

  1. #1
    Registered User blob84's Avatar
    Join Date
    Jun 2010
    Posts
    46

    count processes

    hi, it is only an exercise,
    how many processes are there in 30 seconds?
    I think 30x9 processes?
    It is impossible to count trying the code.
    Code:
    #include <fcntl.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include "/home/blob/Documenti/SO/err.h"
    
    int main(void)
    {
    	int i = 0;
    	int fd[2];
    	pid_t pid0, pid1, pid2, pid3, pid4, pid5;
    	pid_t pid6, pid7, pid8, pid9;
    	pid0 = fork();
    	pid1 = fork();
    	pid2 = fork();
    	pid3 = fork();
    	pid4 = fork();
    	pid5 = fork();
    	pid6 = fork();
    	pid7 = fork();
    	pid8 = fork();
    	pid9 = fork();
    	printf("hello\n");
    	sleep(30);
    	exit(0);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > pid0 = fork();
    Results in two processes.

    > pid1 = fork();
    Two processes call this, resulting in 4 processes.

    Do you see where this is going?

    Assuming that you don't actually run out of process table entries when running this fork-bomb.
    Yarin likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,690
    Quote Originally Posted by blob84 View Post
    hi, it is only an exercise,
    how many processes are there in 30 seconds?
    I think 30x9 processes?
    It is impossible to count trying the code.
    Your question is a little vague.
    Are trying to count how processes were created as a result of your code (in which case, Salem answered)?
    Or how many of your children are still running, at a certain point in time? If so, then google for a Linux IPC tutorial. That should help you out a lot.
    Quote Originally Posted by Salem View Post
    Do you see where this is going?

    Assuming that you don't actually run out of process table entries when running this fork-bomb.
    Haha, it's always so funny seeing people do this.
    But, actually, I don't think it would be so bad, I believe Linux has a safe-guard in place to detect and defuse fork bombing.

  4. #4
    Registered User blob84's Avatar
    Join Date
    Jun 2010
    Posts
    46
    ok it should be 2^10 processes, 1024

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,690
    Correct, if unbridled, your process would spawn 1024 children/grandchildren. But your system may never even let it get that far. You'd have to try it and see

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Uppercase/Lowercase/Word COunt/Char count
    By Charak in forum C Programming
    Replies: 7
    Last Post: 02-23-2011, 08:16 AM
  2. Processes
    By wise_ron in forum C Programming
    Replies: 3
    Last Post: 09-11-2006, 10:22 PM
  3. Again Character Count, Word Count and String Search
    By client in forum C Programming
    Replies: 2
    Last Post: 05-09-2002, 12:40 PM
  4. Replies: 2
    Last Post: 05-05-2002, 02:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21