muze has asked for the wisdom of the Perl Monks concerning the following question:

hello guys... I am very new to perl and using ubuntu 10.10. I tried to start a process (vlc player) using fork in which im successful. But I want vlc player not only to open but also to run a movie or sound on startup. Here is what I tried but, of course it does not work.

$directoryListing = `vlc`.`home/muze/sound.avi`; print $directoryListing; my $pid = fork(); if( $pid == 0 ){ print "VLC Player running\n"; }

So how do I pass sound path as argument to fork()? thnx

UPDATE:

Also, how do I kill this process, lets say, after 10 seconds automatically

Replies are listed 'Best First'.
Re: Passing Process the Argument using fork()
by wind (Priest) on Mar 31, 2011 at 19:40 UTC
    Concatenating backticks will attempt to run each of those independently and simply concatenate the results. Join them together inside the ``.
    $directoryListing = `vlc home/muze/sound.avi`;
    Also, as your script stands right now, your executing vlc independently of the fact that you're forking later.
Re: Passing Process the Argument using fork()
by cdarke (Prior) on Apr 01, 2011 at 07:39 UTC
    how do I pass sound path as argument to fork()?

    You don't, fork does not take any arguments. fork creates an (almost) identical child process to the parent, there is no need to pass any arguments to the child, all the variable values that are in the parent are in the child. Are you perhaps missing exec?

    how do I kill this process, lets say, after 10 seconds automatically

    See alarm, so for example (untested):
    my $g_pid = 0; sub AlarmHandler { kill 'KILL', $g_pid if $g_pid; $g_pid = 0; } local %SIG; $SIG{'ALRM'} = \&AlarmHandler; alarm ($Seconds); $g_pid = fork(); # blah, blah, blah alarm(0); # Turn off the timer
    The kill will invode a SIGCHLD handler, if you have one.