1

Is it possible for a program to create dynamically name processes that it starts? Consider the famous fork bomb code:

 :(){ :|:& };:

or

 import os
 while os.fork() or True: os.fork()

Would it be possible to let it generate a new random process name every time that it executes? Which would make it a lot harder to get rid of. It doesn't necessarily have to be in perl or python, I'd love to see examples in other languages too.

spydon
  • 9,372
  • 6
  • 33
  • 63

1 Answers1

1

It is usually possible to set the process name, but this capability varies from OS to OS. In Perl, we can assign to the $0 variable, which changes the current process name:

for my $i (1 .. 5) {
  fork && next;
  $0 = "foobar: $i";
  sleep 5;
  exit;
}

print for grep /foobar/, `ps aux`;

Which produces the output:

1000      1231  0.0  0.0   7836   552 pts/5    S+   13:32   0:00 foobar: 1
1000      1232  0.0  0.0   7836   552 pts/5    S+   13:32   0:00 foobar: 2
1000      1233  0.0  0.0   7836   552 pts/5    S+   13:32   0:00 foobar: 3
1000      1235  0.0  0.0   7836   552 pts/5    S+   13:32   0:00 foobar: 4
1000      1236  0.0  0.0   7836   552 pts/5    S+   13:32   0:00 foobar: 5

or something similar. I do not know how this would be done, but shell and Python should have similar functionality.

amon
  • 57,091
  • 2
  • 89
  • 149