#!/usr/bin/perl use warnings; use strict; if (-f "./testfile") { !system "rm -f testfile" or die "Couldn't delete already present testfile\n"; } my $pid; my $parent = $$; open (INFILE, "+>testfile") or die "Can't create testfile: $!"; print "This is parent $parent \n"; defined($pid = fork) or die "Cannot fork: $!"; unless($pid) { # Child process is here print "This is child pid $$\n"; exec "cat /dev/urandom > testfile"; } sleep 1; close INFILE; kill -9 => $pid; #### # ./test.pl This is parent 29307 This is child pid 29309 # #### # ps -ef|grep urandom root 29309 1 0 00:53 pts/2 00:00:00 sh -c cat /dev/urandom > testfile root 29310 29309 99 00:53 pts/2 00:00:12 cat /dev/urandom