CSC 357 Lecture Notes Weeks 6 and 7
Introduction to UNIX Processes and Process Control
starts a little utility that runs in the background to check periodically for arriving mail.xbiff &
hornet> xbiff & [1] 14583 hornet> rmiregistry & [2] 14590 hornet> jobs [1] Running xbiff [2] Running rmiregistry hornet> %2 rmiregistry ^C hornet> kill %1 hornet>
char *getenv(const char *name);
gcc -lm
int getrlimit(int resource, struct rlimit *rlp); int setrlimit(int resource, const struct rlimit *rlp);
RLIMIT_AS | Max size in bytes of a process's total memory, as available |
from the sbrk function. | |
RLIMIT_CPU | Max amount of CPU time in seconds. |
RLIMIT_FSIZE | Max size in bytes of a file that may be created. |
RLIMIT_NOFILE | Max number of open files per process. |
RLIMIT_NPROC | Max number of child processes per user ID. |
RLIMIT_STACK | Max size in bytes of the stack. |
struct rlimit { rlim_t rlim_cur; /* current (soft) limit */ rlim_t rlim_max; /* maximum (hard) limit value for rlim_cur */ };
pid_t getpid(); // get ID of current running process
pid_t getppid(); // get ID of parent process
uid_t getuid(); // get user ID of current process
pid_t fork();
int main() {
pid_t pid;
if ((pid = fork()) < 0) { ... /* fail */ } else if (pid == 0) { ... /* child */ } else { ... /* parent */ } }
pid_t wait(int* status)
pid_t waitpid(pid_t pid, int* status, int options)
int execl(const char *path, const char *arg, ... /*, (char *)0 */);
int execlp(const char *file, const char *arg, ... /*, (char *)0 */);
int execle(const char *path, const char *arg, ... /*, (char *)0, char *const envp[] */);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execvP(const char *file, const char *search_path, char *const argv[]);
int main() {
pid_t pid;
if ((pid = fork()) < 0) { ... /* fail */ } else if (pid == 0) { execvp(...) /* child */ } else { ... /* parent */ } }
chmod u+s prog
#! pathnameis considered by the kernel to be executable using the interpreter specified in pathname.
at the top of shell scripts intended to by executed using /bin/tcsh.#!/bin/tcsh