CS330 Introduction to Operating Systems
Some UNIX System Calls / Library Functions
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
perror fork getpid getppid
|
getuid chmod chdir getcwd execl |
execlp exit _exit sleep kill |
wait waitpid signal creat |
open close read write
|
link unlink stat |
pipe dup dup2 brk sbrk |
Include Files(s)
|
<stdio.h> |
Manual Section |
3c |
|
Summary
|
void perror( const char *s); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
|
|
|
Include Files(s)
|
<sys/types.h> <unistd.h> |
Manual Section |
2 |
|
Summary
|
pid_t fork( void ); |
|||
Purpose |
||||
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 |
||||
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 |
||||
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 |
||||
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 |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<unistd.h>
|
Manual Section |
3c |
|
Summary
|
int chdir(const char *path ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
|
Manual Section |
2 |
|
Summary
|
extern char *getcwd( char *buf, size_t size ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
A pointer to the current directory name |
NULL |
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 |
||||
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 |
||||
Return |
Success |
Failure |
Sets errno |
|
Does not return |
-1 |
Yes |
Include Files(s)
|
<stdlib.h> |
Manual Section |
3c |
|
Summary
|
void exit( int status); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
No return |
No return |
|
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
void _exit( void ); |
|||
Purpose |
||||
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 |
||||
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 |
||||
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 |
||||
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 |
||||
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 |
||||
Return |
Success |
Failure |
Sets errno |
|
Signal’s previous disposition |
SIG_ERR (-1) |
Yes |
Include Files(s)
|
<sys/types.h> <fcntl.h> |
Manual Section |
2 |
|
Summary
|
int creat ( const char *path, mode_t mode ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
Lowest available file descriptor. |
-1 |
Yes |
Include Files(s)
|
<sys/types.h> <fcntl.h> |
Manual Section |
2 |
|
Summary
|
int open ( const char *path, int flags, /* mode_t mode */); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
Lowest available file descriptor |
-1 |
Yes |
Some flags are O_RDONLY, O_WRONLY, O_RDWR, O_NDELAY, O_NONBLOCK,
O_APPEND, O_CREAT, O_BINARY
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int close ( int filedescr ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int read ( int filedescr, char *buf, int numbytes ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
Number of characters read |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int write ( int filedescr, char *buf, int numbytes ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
Number of characters written |
-1 |
Yes |
Include Files(s)
|
<sys/types.h> <fcntl.h> |
Manual Section |
2 |
|
Summary
|
int link ( const char *path1, const char *path2); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<unistd.h>
|
Manual Section |
2 |
|
Summary
|
int unlink ( const char *path ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<sys/types.h> |
Manual Section |
2 |
|
Summary
|
int stat ( const char *path, structu stat *buf); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
|
-1 |
Yes |
Fields of the stat structure |
||
Type |
Field name |
Purpose |
dev_t |
st_dev |
/* device that file resides on */ |
ino_t |
st_ino |
/* this file’s number */ |
u_short |
st_mode |
/* protection */ |
short |
st_nlink; |
/* number of hard links to the file */ |
short |
st_uid; |
/* user ID of owner */ |
short |
st_gid; |
/* group ID of owner */ |
dev_t |
st_rdev; |
/* the device identifier (special files only) */ |
off_t |
st_size; |
/* total size of file, in bytes */ |
time_t |
st_atime; |
/* file data last access time */ |
time_t |
st_mtime; |
/* file data last modify time */ |
time_t |
st_ctime; |
/* file data last status change time */ |
long |
st_blksize; |
/* preferred blocksize for file system I/O */ |
long |
st_blocks; |
/* actual number of blocks allocated */ |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int pipe ( int filedescr[2]); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int dup ( int filedescr); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
file descriptor (nonnegative) |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int dup2 ( int filedescr1, int filedescr2); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
filedescr2 |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int brk (void *endds); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
0 |
-1 |
Yes |
Include Files(s)
|
<unistd.h> |
Manual Section |
2 |
|
Summary
|
int sbrk (intptr_t incr); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
previous break value |
(void *)-1 |
Yes |