Download presentation
Presentation is loading. Please wait.
1
The Process - Part II
2
Process Attributes Each UNIX process is associated with a number of attributes which help the system control the running and scheduling of processes, maintain the security of the file system and so on –process id –environment –effective user-id –privileges
3
The process-id A process can obtain its own process-id by using the getpid() function call.
7
Process group and process group-ids Unix allows processes to be placed into groups. For example processes are connected by pipes from the command line, they are typically placed into a process group. whoawk ‘(print $1)’Sort -u
8
Process groups Process groups are useful when you want to handle a set of processes as a whole using IPC mechanism called signals. Each process group is denoted by a process group-id of type pid_t. Usage: #include pid_t getpgrp (void);
9
Changing process group Usage #include int setpgid (pid_t pid, pid_t pgid);
10
Session and session-ids Each process group belongs to a session. A session is about a process’s connection to a connecting terminal. All processes explicitly or implicitly created after a user logs in belong to a session related to their current terminal. A session is a collection of a single foreground process group using the terminal and one or more background processes.
11
Session-id A session is identified by a session-id of type pid_t. A process can obtain its current session-id with a call to getsid as follows: Usage #include pid_t getsid(pid_t pid);
12
Session-d continued If getsid is supplied a value of 0 then it returns the session-id of the calling process otherwise the session-id of the process identified by pid is returned. The idea of a session is useful with background or daemon process. A daemon process is simply a process which does not have a controlling terminal.
13
Session continued An example of a daemon process is a cron, which executes commands at specific times and dates. A daemon can set itself to be in a session without a controlling terminal by calling the setsid system call, and moving itself into a new session.
14
Session id Usage #include pid_t setsid(void);
15
The environment variable The environment of a process is simply a collection of null-terminated strings. A programmer can make direct use of the environment of a process by adding an extra parameter envp to the parameter list of the main function within a program. –main(int argc, char **argv, char **envp) { // do something }
17
To modify the environment from within a process /* setmyenv.c set environment for program */ main() { char *argv[2], *envp[3]; argv[0] = “showmyenv”; argv[1] = (char *)0; envp[0] = “foo=bar”; envp[1] = “bar=foo”; envp[2] = (char *)0; execve(“./showmyenv”, argv, envp); perror(“execve failed\n”); }
18
Getting specific variable The getenv system call can be used to get specific variables in the environment. Usage #include char *getenv(const char *name); main() { printf(“PATH = %s\n”, getenv(“PATH”); } A similar putenv(“NEWVARIABLE = value”); exists for modifying the env.
19
Obtaining the user- and group-ids
20
Setting the e-user- and group-ids
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.