CS330 Introduction to Operating Systems

Some UNIX System Calls / Library Functions

 

 

Page 1

Page 2

Page 3

Page 4

perror

fork

getpid

getppid

 

getuid

chmod

chdir

getcwd

execl

execlp

exit

_exit

sleep

kill

wait

waitpid

signal

 

 

 

 

Include Files(s)

 

<stdio.h>

Manual Section

3c

Summary

 

void perror( const char *s);

Purpose

Print an error message based on the value of errno.

Return

Success

Failure

Sets errno

 

 

 

 

 

Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

pid_t fork( void );

Purpose

Create a child process.

Return

Success

Failure

Sets errno

0 in child, child PID in parent

-1

Yes

 

 

Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

pid_t getpid( void );

Purpose

Determine the process identifier (pid) for the current process.

Return

Success

Failure

Sets errno

The process ID

-1

Yes

 

 

Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

pid_t getppid( void );

Purpose

Determine the process identifier of the parent process.

Return

Success

Failure

Sets errno

The parent process ID

-1

Yes

 

 


Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

uid_t getuid( void );

Purpose

Obtain the user’s identifier (uid).

Return

Success

Failure

Sets errno

The requested identifier

 

 

 

 


Include Files(s)

 

<sys/types.h>

<sys/stat.h>

Manual Section

2

Summary

 

int chmod( const char *path,

           mode_t mode );

Purpose

Change the access permissions of a file or directory.

Return

Success

Failure

Sets errno

0

-1

Yes

 

 


Include Files(s)

 

<unistd.h>

 

Manual Section

3c

Summary

 

int chdir( char *buf,

           size_t size );

Purpose

Change the working directory of a process.

Return

Success

Failure

Sets errno

A pointer to the current directory name

NULL

Yes

 

 


Include Files(s)

 

<unistd.h>

 

Manual Section

2

Summary

 

extern char *getcwd( const char *path );

Purpose

Change the working directory of a process.

Return

Success

Failure

Sets errno

0

-1

Yes

 

 

Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

int execl( const char *file_pathname,

           const char *arg0,

...        . . .

           const char *argn,

           char * /* NULL */ );

Purpose

Obtain code to execute from the executable file specified by a filename optionally preceded by a directory path.

Return

Success

Failure

Sets errno

Does not return

-1

Yes

 

Include Files(s)

 

<sys/types.h>

<unistd.h>

Manual Section

2

Summary

 

int execlp( const char *file,

           const char *arg0,

...        . . .

           const char *argn,

           char * /* NULL */ );

Purpose

Obtain code to execute from the executable file specified by the filename, searching the directories given in the PATH environment variable.

Return

Success

Failure

Sets errno

Does not return

-1

Yes

 

 

Include Files(s)

 

<stdlib.h>

Manual Section

3c

Summary

 

void exit( int status);

Purpose

Terminate the current process by executing the at exit functions, cleaning up standard input/output with _cleanup, and calling _exit to terminate the process.

Return

Success

Failure

Sets errno

No return

No return

 

 

 

Include Files(s)

 

<unistd.h>

Manual Section

2

Summary

 

void _exit( void );

Purpose

Terminate the current process.

Return

Success

Failure

Sets errno

Does not return

Does not return

 

 

 

Include Files(s)

 

<unistd.h>

Manual Section

3c

Summary

 

unsigned sleep( unsigned seconds );

Purpose

Suspend the current process for the specified number of seconds.

Return

Success

Failure

Sets errno

Amount of unslept time remaining

 

 

 

 

Include Files(s)

 

<sys/types.h>

<signal.h>

Manual Section

2

Summary

 

int kill( pid_t pid,

          int sig );

Purpose

Send a specified signal to a specified process.

Return

Success

Failure

Sets errno

0

-1

Yes


Include Files(s)

 

<sys/types.h>

<sys/wait.h>

Manual Section

2

Summary

 

pid_t wait( int *stat_loc );

Purpose

Wait for a signal; ordinarily this will be the signal from a terminating child process.

Return

Success

Failure

Sets errno

Child PID

-1

Yes

 

Value stored at stat_loc:

Child terminated normally:

 

byte 3

byte 2

byte 1

byte 0

 

 

exit code

0

 

Child terminated due to an uncaught signal:

 

byte 3

byte 2

byte 1

byte 0

 

 

0

signal #

 

 

Include Files(s)

 

<sys/types.h>

<sys/wait.h>

Manual Section

2

Summary

 

pid_t waitpid( pid_t pid,

               int *stat_loc,

               int options );

Purpose

Wait for a signal from a specified process or group of processes. Ordinarily this will be the signal from a terminating child. 

Return

Success

Failure

Sets errno

Child PID or 0

-1

Yes

 

 

Include Files(s)

 

<signal.h>

 

Manual Section

2

Summary

 

void *signal( int sig,

              void (*disp) (int))) (int);

Purpose

Set the entry in the signal handler table for a specified type of signal.

Return

Success

Failure

Sets errno

Signal’s previous disposition

SIG_ERR

(-1)

Yes