16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

struct timeval {<br />

long tv_sec; /* seconds since 00:00:00 GMT, 1 Jan 1970 */<br />

long tv_usec; /* and microseconds */<br />

};<br />

114<br />

Processes I<br />

If <strong>the</strong> "stick bit" is set, <strong>the</strong> executable program's read-only text is left in swap, so that it will start faster next time.<br />

! File Mode creation Mask<br />

int umask(int mask)<br />

(This is one of <strong>the</strong> few system calls that cannot fail and does not have an error return<br />

{exit, getpid, getpgrp, getppid, getuid,<br />

geteuid, getgid, getegid, umask})<br />

The file creation mask is used when a new file or directory is created. The mask specifies which bits in <strong>the</strong> new<br />

file are to cleared. If <strong>the</strong> file mode creation mask is octal 022, <strong>the</strong> group-write bit is off giving an actual mode of<br />

octal 0644.<br />

! Major and Minor Device Numbers<br />

For disk drives <strong>the</strong> major number usually specifies <strong>the</strong> disk controller and <strong>the</strong> minor number specifies both <strong>the</strong> drive<br />

and <strong>the</strong> partition on <strong>the</strong> drive.<br />

For example a controller that supports up to 8 drives can use minor device numbers 0-7 for up to 8 partitions on<br />

<strong>the</strong> first drive, 8-15 for partitions on <strong>the</strong> second drive, and so on.<br />

! Directories<br />

int mkdir(char *pathname, int mode); /* 14 byte name, 2 byte mode */<br />

int system(char *string);<br />

char buff[1024], dirname[1024];<br />

sprintf(buff, "mkdir %s", dirname);<br />

if (system(buff) != 0) {<br />

/* error handling */<br />

}<br />

! Current <strong>Working</strong> Directory<br />

Each process has associated <strong>with</strong> it a cwd. A process can change its cwd <strong>with</strong> chdir.<br />

int chdir(char *pathname);<br />

! Process Group ID<br />

Every process is a member of a process group. It is possible to send a signal using <strong>the</strong> kill system call to all<br />

processes belonging to a specified process group.<br />

The value of <strong>the</strong> process group ID is obtained by calling getpgrp system call. Under System V a process is only<br />

able to change its process group ID to be equal to its process ID, effectively becoming a process group leader.<br />

int setpgrp();<br />

! Terminal Group ID and Control Terminal<br />

Each process can be a member of a terminal group. The terminal group ID is <strong>the</strong> process ID of <strong>the</strong> process group<br />

leader that opened <strong>the</strong> terminal.<br />

The terminal group ID identifies <strong>the</strong> control terminal for a process group. When <strong>the</strong> process group leader for a<br />

terminal calls exit, a hangup signal is sent to each process in <strong>the</strong> process group.<br />

! Socket Group ID<br />

BSD supports <strong>the</strong> notion of a process group of sockets. Each socket that is open has a socket group ID.<br />

! Time-of-Day<br />

BSD provides gettimeofday system call<br />

#include <br />

int gettimeofday(struct timval *tvalptr, struct timezone *tzoneptr);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!