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 |
||||
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( char *buf, size_t size ); |
|||
Purpose |
||||
Return |
Success |
Failure |
Sets errno |
|
A pointer to the current directory name |
NULL |
Yes |
Include Files(s)
|
|
Manual Section |
2 |
|
Summary
|
extern char *getcwd( const char *path ); |
|||
Purpose |
||||
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 |
||||
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 |