Copyright © tutorialspoint.com

# PERL syscall Function

## Syntax

syscall EXPR, LIST

## Definition and Usage

Lets Perl to call corresponding UNIX C system calls directly. It relies on the existence of the set of Perl header files syscall.ph which declare all these calls. The script h2ph which is normally executed when Perl is installed sets up the syscall.ph files. Each call has the same name as the equivalent UNIX system call with the "SYS_" prefix. As these calls actually pass control to the relevant C system, function care must be taken with passing parameters.

The first element in the list used as an argument to syscall() itself is the name corresponding to the UNIX system call (i.e. with the "SYS_" prefix). The next elements in the list are interpreted as parameters to this call. Numeric values are passed as the C type int. String values are passed as pointers to arrays. The length of these strings must be able to cope with any value assigned to that parameter in the call.

## Return Value

- -1 on failure of system call

- Value returned by system function

## Example

Try out following example:

    #!/usr/bin/perl -w

    require("syscall.ph");
    $pid = syscall(&SYS_getpid);

    print "PID of this process is $pid\n";

    # To create directory use the following
    $string = "newdir";
    syscall( &SYS_mkdir, $string );

It will produce following result:

    PID of this process is 16335

Copyright © tutorialspoint.com