Next Previous Contents

18. System Call Functions

18.1 getegid

Synopsis

Get the effective group id of the current process

Usage

Int_Type getegid ()

Description

The getegid function returns the effective group ID of the current process.

Notes

This function is not supported by all systems.

See Also

getgid, geteuid, setgid

18.2 geteuid

Synopsis

Get the effective user-id of the current process

Usage

Int_Type geteuid ()

Description

The geteuid function returns the effective user-id of the current process.

Notes

This function is not supported by all systems.

See Also

getuid, setuid, setgid

18.3 getgid

Synopsis

Get the group id of the current process

Usage

Integer_Type getgid ()

Description

The getgid function returns the real group id of the current process.

Notes

This function is not supported by all systems.

See Also

getpid, getppid

18.4 getpid

Synopsis

Get the current process id

Usage

Integer_Type getpid ()

Description

The getpid function returns the current process identification number.

See Also

getppid, getgid

18.5 getppid

Synopsis

Get the parent process id

Usage

Integer_Type getppid ()

Description

The getpid function returns the process identification number of the parent process.

Notes

This function is not supported by all systems.

See Also

getpid, getgid

18.6 getpriority

Synopsis

Get a process's scheduling priority

Usage

result = getpriority (which, who)

Description

The setpriority function may be used to obtain the kernel's scheduling priority for a process, process group, or a user depending upon the values of the which and who parameters. Specifically, if the value of which is PRIO_PROCESS, then the value of who specifies the process id of the affected process. If which is PRIO_PGRP, then who specifies a process group id. If which is PRIO_USER, then the value of who is interpreted as a user id. For the latter two cases, where which refers to a set of processes, the value returned corresponds to the highest priority of a process in the set. A value of 0 may be used for who to denote the process id, process group id, or real user ID of the current process.

Upon success, the function returns the specified priority value. If an error occurs, the function will return NULL with errno set accordingly.

See Also

setpriority, getpid, getppid

18.7 getuid

Synopsis

Get the user-id of the current process

Usage

Int_Type getuid ()

Description

The getuid function returns the user-id of the current process.

Notes

This function is not supported by all systems.

See Also

getuid, getegid

18.8 kill

Synopsis

Send a signal to a process

Usage

Integer_Type kill (Integer_Type pid, Integer_Type sig)

Description

This function may be used to send a signal given by the integer sig to the process specified by pid. The function returns zero upon success or -1 upon failure setting errno accordingly.

Example

The kill function may be used to determine whether or not a specific process exists:

    define process_exists (pid)
    {
       if (-1 == kill (pid, 0))
         return 0;     % Process does not exist
       return 1;
    }

Notes

This function is not supported by all systems.

See Also

getpid

18.9 mkfifo

Synopsis

Create a named pipe

Usage

Int_Type mkfifo (String_Type name, Int_Type mode)

Description

The mkfifo attempts to create a named pipe with the specified name and mode (modified by the process's umask). The function returns 0 upon success, or -1 and sets errno upon failure.

Notes

Not all systems support the mkfifo function and even on systems that do implement the mkfifo system call, the underlying file system may not support the concept of a named pipe, e.g, an NFS filesystem.

See Also

stat_file

18.10 setgid

Synopsis

Set the group-id of the current process

Usage

Int_Type setgid (Int_Type gid)

Description

The setgid function sets the effective group-id of the current process. It returns zero upon success, or -1 upon error and sets errno appropriately.

Notes

This function is not supported by all systems.

See Also

getgid, setuid

18.11 setpgid

Synopsis

Set the process group-id

Usage

Int_Type setpgid (Int_Type pid, Int_Type gid)

Description

The setpgid function sets the group-id gid of the process whose process-id is pid. If pid is 0, then the current process-id will be used. If pgid is 0, then the pid of the affected process will be used.

If successful 0 will be returned, otherwise the function will return -1 and set errno accordingly.

Notes

This function is not supported by all systems.

See Also

setgid, setuid

18.12 setpriority

Synopsis

Set the scheduling priority for a process

Usage

Int_Type setpriority (which, who, prio)

Description

The setpriority function may be used to set the kernel's scheduling priority for a process, process group, or a user depending upon the values of the which and who parameters. Specifically, if the value of which is PRIO_PROCESS, then the value of who specifies the process id of the affected process. If which is PRIO_PGRP, then who specifies a process group id. If which is PRIO_USER, then the value of who is interpreted as a user id. A value of 0 may be used for who to denote the process id, process group id, or real user ID of the current process.

Upon sucess, the setpriority function returns 0. If an error occurs, -1 is returned and errno will be set accordingly.

Example

The getpriority and setpriority functions may be used to implement a nice function for incrementing the priority of the current process as follows:

   define nice (dp)
   {
      variable p = getpriority (PRIO_PROCESS, 0);
      if (p == NULL)
        return -1;
      variable s = setpriority (PRIO_PROCESS, 0, p + dp);
      if (s == -1)
        return -1;
      return getpriority (PRIO_PROCESS, 0);
   }

Notes

Priority values are sometimes called "nice" values. The actual range of priority values is system dependent but commonly range from -20 to 20, with -20 being the highest scheduling priority, and +20 the lowest.

See Also

getpriority, getpid

18.13 setuid

Synopsis

Set the user-id of the current process

Usage

Int_Type setuid (Int_Type id)

Description

The setuid function sets the effective user-id of the current process. It returns zero upon success, or -1 upon error and sets errno appropriately.

Notes

This function is not supported by all systems.

See Also

setgid, setpgid, getuid, geteuid

18.14 sleep

Synopsis

Pause for a specified number of seconds

Usage

sleep (Double_Type n)

Description

The sleep function delays the current process for the specified number of seconds. If it is interrupted by a signal, it will return prematurely.

Notes

Not all system support sleeping for a fractional part of a second.

18.15 system

Synopsis

Execute a shell command

Usage

Integer_Type system (String_Type cmd)

Description

The system function may be used to execute the string expression cmd in an inferior shell. This function is an interface to the C system function which returns an implementation-defined result. On Linux, it returns 127 if the inferior shell could not be invoked, -1 if there was some other error, otherwise it returns the return code for cmd.

Example

    define dir ()
    {
       () = system ("DIR");
    }
displays a directory listing of the current directory under MSDOS or VMS.

See Also

system_intr, system_intr<@@ref>new_processnew_process, popen

18.16 system_intr

Synopsis

Execute a shell command

Usage

Integer_Type system_intr (String_Type cmd)

Description

The system_intr function performs the same task as the system function, except that the SIGINT signal will not be ignored by the calling process. This means that if a S-Lang script calls system_intr function, and Ctrl-C is pressed, both the command invoked by the system_intr function and the script will be interrupted. In contrast, if the command were invoked using the system function, only the command called by it would be interrupted, but the script would continue executing.

See Also

system, system<@@ref>new_processnew_process, popen

18.17 umask

Synopsis

Set the file creation mask

Usage

Int_Type umask (Int_Type m)

Description

The umask function sets the file creation mask to the value of m and returns the previous mask.

See Also

stat_file

18.18 uname

Synopsis

Get the system name

Usage

Struct_Type uname ()

Description

The uname function returns a structure containing information about the operating system. The structure contains the following fields:

       sysname  (Name of the operating system)
       nodename (Name of the node within the network)
       release  (Release level of the OS)
       version  (Current version of the release)
       machine  (Name of the hardware)

Notes

Not all systems support this function.

See Also

getenv


Next Previous Contents