精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● 编程世界>>其他>>Unix C Programming FAQ

主题:Unix C Programming FAQ
发信人: xiaomiao()
整理人: jinhu(1999-06-30 20:15:20), 站内信件
在网上发现一篇Unix C Programming FAQ,读完后觉得受益非浅,转贴如此:

                Unix Programming FAQ

1. Process Control
  1.1 Creating new processes: fork()
    1.1.1 What does fork() do?
    1.1.2 What's the difference between fork() and vfork()?
    1.1.3 Why use _exit rather than exit in the child branch of a fork
?
  1.2 Environment variables
    1.2.1 How can I get/set an environment variable from a program?
    1.2.2 How can I read the whole environment?
  1.3 How can I sleep for less than a second?
  1.4 How can I get a finer-grained version of alarm()?
  1.5 How can a parent and child process communicate?
  1.6 How do I get rid of zombie processes?
    1.6.1 What is a zombie?
    1.6.2 How do I prevent them from occuring?
  1.7 How do I get my program to act like a daemon?
  1.8 How can I look at process in the system like ps does?
  1.9 Given a pid, how can I tell if it's a running program?
  1.10 What's the return value of system/pclose/waitpid?
  1.11 How do I find out about a process' memory usage?
  1.12 Why do processes never decrease in size?
  1.13 How do I change the name of my program (as seen by `ps')?
  1.14 How can I find a process' executable file?
    1.14.1 So where do I put my configuration files then?
  1.15 Why doesn't my process get SIGHUP when its parent dies?
  1.16 How can I kill all descendents of a process?

2. General File handling (including pipes and sockets)
  2.1 How to manage multiple connections?
    2.1.1 How do I use select()?
    2.1.2 How do I use poll()?
    2.1.3 Can I use SysV IPC at the same time as select or poll?
  2.2 How can I tell when the other end of a connection shuts down?
  2.3 Best way to read directories?
  2.4 How can I find out if someone else has a file open?
  2.5 How do I `lock' a file?
  2.6 How do I find out if a file has been updated by another process?

  2.7 How does the `du' utility work?
  2.8 How do I find the size of a file?
  2.9 How do I expand `~' in a filename like the shell does?
  2.10 What can I do with named pipes (FIFOs)?
    2.10.1 What is a named pipe?
    2.10.2 How do I create a named pipe?
    2.10.3 How do I use a named pipe?
    2.10.4 Can I use a named pipe across NFS?
    2.10.5 Can multiple processes write to the pipe simultaneously?
    2.10.6 Using named pipes in applications

3. Terminal I/O
  3.1 How can I make my program not echo input?
  3.2 How can I read single characters from the terminal?
  3.3 How can I check and see if a key was pressed?
  3.4 How can I move the cursor around the screen?
  3.5 What are pttys?
  3.6 How to handle a serial port or modem?
    3.6.1 Serial device names and types
    3.6.2 Setting up termios flags
      3.6.2.1 c_iflag
      3.6.2.2 c_oflag
      3.6.2.3 c_cflag
      3.6.2.4 c_lflag
      3.6.2.5 c_cc

4. System Information
  4.1 How can I tell how much memory my system has?
  4.2 How do I check a user's password?
    4.2.1 How do I get a user's password?
    4.2.2 How do I get shadow passwords by uid?
    4.2.3 How do I verify a user's password?

5. Miscellaneous programming
  5.1 How do I compare strings using wildcards?
    5.1.1 How do I compare strings using filename patterns?
    5.1.2 How do I compare strings using regular expressions?
  5.2 What's the best way to send mail from a program?
    5.2.1 The simple method: /bin/mail
    5.2.2 Invoking the MTA directly: /usr/lib/sendmail
      5.2.2.1 Supplying the envelope explicitly
      5.2.2.2 Allowing sendmail to deduce the recipients

6. Use of tools
  6.1 How can I debug the children after a fork?
  6.2 How to build library from other libraries?
  6.3 How to create shared libraries / dlls?
  6.4 Can I replace objects in a shared library?
  6.5 How can I generate a stack dump from within a running program?

1. Process Control
******************

1.1 Creating new processes: fork()
==================================

1.1.1 What does fork() do?
--------------------------

     #include <sys/types.h>
     #include <unistd.h>
     
     pid_t fork(void);

The `fork()' function is used to create a new process from an existing

process.  The new process is called the child process, and the existin
g
process is called the parent.  You can tell which is which by checking
 the
return value from `fork()'.  The parent gets the child's pid returned 
to
him, but the child gets 0 returned to him.  Thus this simple code
illustrate's the basics of it.

     pid_t pid;
     
     switch (pid = fork())
     {
     case -1:
         /* Here pid is -1, the fork failed */
         /* Some possible reasons are that you're */
         /* out of process slots or virtual memory */
         perror("The fork failed!");
         break;
     
     case 0:
         /* pid of zero is the child */
         /* Here we're the child...what should we do? */
         /* ... */
         /* but after doing it, we should do something like: */
         _exit(0);
     
     default:
         /* pid greater than zero is parent getting the child's pid */

         printf("Child's pid is %d\n",pid);
     }

Of course, one can use `if()... else...' instead of `switch()', but th
e
above form is a useful idiom.

Of help when doing this is knowing just what is and is not inherited b
y the
child.  This list can vary depending on Unix implementation, so take i
t
with a grain of salt.  Note that the child gets *copies* of these thin
gs,
not the real thing.

Inherited by the child from the parent:

   * process credentials (real/effective/saved UIDs and GIDs)

   * environment

   * stack

   * memory

   * open file descriptors (note that the underlying file positions ar
e
     shared between the parent and child, which can be confusing)

   * close-on-exec flags

   * signal handling settings

   * nice value

   * scheduler class

   * process group ID

   * session ID

   * current working directory

   * root directory

   * file mode creation mask (umask)

   * resource limits

   * controlling terminal

Unique to the child:

   * process ID

   * different parent process ID

   * Own copy of file descriptors and directory streams.

   * process, text, data and other memory locks are NOT inherited.

   * process times, in the tms struct

   * resource utilizations are set to 0

   * pending signals initialized to the empty set

   * timers created by timer_create not inherited

   * asynchronous input or output operations not inherited

1.1.2 What's the difference between fork() and vfork()?
-------------------------------------------------------

Some systems have a system call `vfork()', which was originally design
ed as
a lower-overhead version of `fork()'. Since `fork()' involved copying 
the
entire address space of the process, and was therefore quite expensive
, the
`vfork()' function was introduced (in 3.0BSD).

*However*, since `vfork()' was introduced, the implementation of `fork
()'
has improved drastically, most notably with the introduction of
`copy-on-write', where the copying of the process address space is
transparently faked by allowing both processes to refer to the same
physical memory until either of them modify it. This largely removes t
he
justification for `vfork()'; indeed, a large proportion of systems now
 lack
the original functionality of `vfork()' completely. For compatibility,

though, there may still be a `vfork()' call present, that simply calls

`fork()' without attempting to emulate all of the `vfork()' semantics.


As a result, it is *very* unwise to actually make use of any of the
differences between `fork()' and `vfork()'. Indeed, it is probably unw
ise
to use `vfork()' at all, unless you know exactly *why* you want to.

The basic difference between the two is that when a new process is cre
ated
with `vfork()', the parent process is temporarily suspended, and the c
hild
process might borrow the parent's address space. This strange state of

affairs continues until the child process either exits, or calls
`execve()', at which point the parent process continues.

This means that the child process of a `vfork()' must be careful to av
oid
unexpectedly modifying variables of the parent process. In particular,
 the
child process must *not* return from the function containing the `vfor
k()'
call, and it must *not* call `exit()' (if it needs to exit, it should 
use
`_exit()'; actually, this is also true for the child of a normal `fork
()').

1.1.3 Why use _exit rather than exit in the child branch of a fork?
-------------------------------------------------------------------

There are a few differences between `exit()' and `_exit()' that become

significant when `fork()', and especially `vfork()', is used.

The basic difference between `exit()' and `_exit()' is that the former

performs clean-up related to user-mode constructs in the library, and 
calls
user-supplied cleanup functions, whereas the latter performs only the

kernel cleanup for the process.

In the child branch of a `fork()', it is normally incorrect to use
`exit()', because that can lead to stdio buffers being flushed twice, 
and
temporary files being unexpectedly removed. In C++ code the situation 
is
worse, because destructors for static objects may be run incorrectly.

(There are some unusual cases, like daemons, where the *parent* should
 call
`_exit()' rather than the child; the basic rule, applicable in the
overwhelming majority of cases, is that `exit()' should be called only
 once
for each entry into `main'.)

In the child branch of a `vfork()', the use of `exit()' is even more
dangerous, since it will affect the state of the *parent* process.

1.2 Environment variables
=========================

1.2.1 How can I get/set an environment variable from a program?
---------------------------------------------------------------

Getting the value of an environment variable is done by using `getenv(
)'.

     #include <stdlib.h>
     
     char *getenv(const char *name);

Setting the value of an environment variable is done by using `putenv(
)'.

     #include <stdlib.h>
     
     int putenv(char *string);

The string passed to putenv must *not* be freed or made invalid, since
 a
pointer to it is kept by `putenv()'.  This means that it must either b
e a
static buffer or allocated off the heap.  The string can be freed if t
he
environment variable is redefined or deleted via another call to `pute
nv()'.

Remember that environment variables are inherited; each process has a

separate copy of the environment. As a result, you can't change the va
lue
of an environment variable in another process, such as the shell.

Suppose you wanted to get the value for the `TERM' environment variabl
e.
You would use this code:

     char *envvar;
     
     envvar=getenv("TERM");
     
     printf("The value for the environment variable TERM is ");
     if(envvar)
     {
         printf("%s\n",envvar);
     }
     else
     {
         printf("not set.\n");
     }

Now suppose you wanted to create a new environment variable called `MY
VAR',
with a value of `MYVAL'.  This is how you'd do it.

     static char envbuf[256];
     
     sprintf(envbuf,"MYVAR=%s","MYVAL");
     
     if(putenv(envbuf))
     {
         printf("Sorry, putenv() couldn't find the memory for %s\n",en
vbuf);
         /* Might exit() or something here if you can't live without i
t */
     }

1.2.2 How can I read the whole environment?
-------------------------------------------

If you don't know the names of the environment variables, then the
`getenv()' function isn't much use. In this case, you have to dig deep
er
into how the environment is stored.

A global variable, `environ', holds a pointer to an array of pointers 
to
environment strings, each string in the form `"NAME=value"'. A `NULL'

pointer is used to mark the end of the array. Here's a trivial program
 to
print the current environment (like `printenv'):

     #include <stdio.h>
     
     extern char **environ;
     
     int main()
     {
         char **ep = environ;
         char *p;
         while ((p = *ep++))
             printf("%s\n", p);
         return 0;
     }

In general, the `environ' variable is also passed as the third, option
al,
parameter to `main()'; that is, the above could have been written:

     #include <stdio.h>
     
     int main(int argc, char **argv, char **envp)
     {
         char *p;
         while ((p = *envp++))
             printf("%s\n", p);
         return 0;
     }

However, while pretty universally supported, this method isn't actuall
y
defined by the POSIX standards. (It's also less useful, in general.)

1.3 How can I sleep for less than a second?
===========================================

The `sleep()' function, which is available on all Unixes, only allows 
for a
duration specified in seconds. If you want finer granularity, then you
 need
to look for alternatives:

   * Many systems have a function `usleep()'

   * You can use `select()' or `poll()', specifying no file descriptor
s to
     test; a common technique is to write a `usleep()' function based 
on
     either of these (see the comp.unix.questions FAQ for some example
s)

   * If your system has itimers (most do), you can roll your own `usle
ep()'
     using them (see the BSD sources for `usleep()' for how to do this
)

   * If you have POSIX realtime, there is a `nanosleep()' function

Whichever route you choose, it is important to realise that you may be

constrained by the timer resolution of the system (some systems allow 
very
short time intervals to be specified, others have a resolution of, say
,
10ms and will round all timings to that). Also, as for `sleep()', the 
delay
you specify is only a *minimum* value; after the specified period elap
ses,
there will be an indeterminate delay before your process next gets
scheduled.

1.4 How can I get a finer-grained version of alarm()?
=====================================================

Modern Unixes tend to implement alarms using the `setitimer()' functio
n,
which has a higher resolution and more options than the simple `alarm(
)'
function. One should generally assume that `alarm()' and
`setitimer(ITIMER_REAL)' may be the same underlying timer, and accessi
ng it
both ways may cause confusion.

Itimers can be used to implement either one-shot or repeating signals;

also, there are generally 3 separate timers available:

`ITIMER_REAL'
     counts real (wall clock) time, and sends the `SIGALRM' signal

`ITIMER_VIRTUAL'
     counts process virtual (user CPU) time, and sends the `SIGVTALRM'

     signal

`ITIMER_PROF'
     counts user and system CPU time, and sends the `SIGPROF' signal; 
it is
     intended for interpreters to use for profiling.

Itimers, however, are not part of many of the standards, despite havin
g
been present since 4.2BSD. The POSIX realtime extensions define a simi
lar,
but different, function: `settimer()'. There are also functions define
d to
query the resolution of POSIX timers.

1.5 How can a parent and child process communicate?
===================================================

A parent and child can communicate through any of the normal inter-pro
cess
communication schemes (pipes, sockets, message queues, shared memory),
 but
also have some special ways to communicate that take advantage of thei
r
relationship as a parent and child.

One of the most obvious is that the parent can get the exit status of 
the
child.

Since the child inherits file descriptors from its parent, the parent 
can
open both ends of a pipe, fork, then the parent close one end and the 
child
close the other end of the pipe.  This is what happens when you call t
he
`popen()' routine to run another program from within yours, i.e. you c
an
write the the file descriptor returned from popen() and the child proc
ess
sees it as its stdin, and you can read from the file descriptor and se
e
what the program wrote to it's stdout.

Also, the child process inherits memory segments mmapped anonymously (
or by
mmapping the special file `/dev/zero') by the parent; these shared mem
ory
segments are not accessible from unrelated processes.

1.6 How do I get rid of zombie processes?
=========================================

1.6.1 What is a zombie?
-----------------------

When a program forks and the child finishes before the parent, the ker
nel
still keeps some of its information about the child in case the parent

might need it - for example, the parent may need to check the child's 
exit
status.  To be able to get this information, the parent calls `wait()'
;
when this happens, the kernel can discard the information.

In the interval between the child terminating and the parent calling
`wait()', the child is said to be a `zombie'.  (If you do `ps', the ch
ild
will have a `Z' in its status field to indicate this.)  Even though it
's
not running, it's still taking up an entry in the process table.  (It

consumes no other resources, but some utilities may show bogus figures
 for
e.g. CPU usage; this is because some parts of the process table entry 
have
been overlaid by accounting info to save space.)

This is not good, as the process table has a fixed number of entries a
nd it
is possible for the system to run out of them. Even if the system does
n't
run out, there is a limit on the number of processes each user can run
,
which is usually smaller than the system's limit. This is one of the
reasons why you should always check if `fork()' failed, by the way!

If the parent terminates without calling wait(), the child is `adopted
' by
`init', which handles the work necessary to cleanup after the child.  
(This
is a special system program with process ID 1 - it's actually the firs
t
program to run after the system boots up).

1.6.2 How do I prevent them from occuring?
------------------------------------------

You need to ensure that your parent process calls `wait()' (or `waitpi
d()',
`wait3()', etc.) for every child process that terminates; or, on some

systems, you can instruct the system that you are uninterested in chil
d
exit states.

Another approach is to `fork()' *twice*, and have the immediate child

process exit straight away. This causes the grandchild process to be
orphaned, so the init process is responsible for cleaning it up. For c
ode
to do this, see the function `fork2()' in the examples section.

To ignore child exit states, you need to do the following (check your

system's manpages to see if this works):

         struct sigaction sa;
         sa.sa_handler = SIG_IGN;
     #ifdef SA_NOCLDWAIT
         sa.sa_flags = SA_NOCLDWAIT;
     #else
         sa.sa_flags = 0;
     #endif
         sigemptyset(&sa.sa_mask);
         sigaction(SIGCHLD, &sa, NULL);

If this is successful, then the `wait()' functions are prevented from

working; if any of them are called, they will wait until *all* child
processes have terminated, then return failure with `errno == ECHILD'.


The other technique is to catch the SIGCHLD signal, and have the signa
l
handler call `waitpid()' or `wait3()'. See the examples section for a

complete program.

1.7 How do I get my program to act like a daemon?
=================================================

A "daemon" process is usually defined as a background process that doe
s not
belong to a terminal session. Many system services are performed by
daemons; network services, printing etc.

Simply invoking a program in the background isn't really adequate for 
these
long-running programs; that does not correctly detach the process from
 the
terminal session that started it. Also, the conventional way of starti
ng
daemons is simply to issue the command manually or from an rc script; 
the
daemon is expected to put *itself* into the background.

Here are the steps to become a daemon:

  1. `fork()' so the parent can exit, this returns control to the comm
and
     line or shell invoking your program.  This step is required so th
at
     the new process is guaranteed not to be a process group leader. T
he
     next step, `setsid()', fails if you're a process group leader.

  2. `setsid()' to become a process group and session group leader. Si
nce a
     controlling terminal is associated with a session, and this new
     session has not yet acquired a controlling terminal our process n
ow
     has no controlling terminal, which is a Good Thing for daemons.

  3. `fork()' again so the parent, (the session group leader), can exi
t.
     This means that we, as a non-session group leader, can never rega
in a
     controlling terminal.

  4. `chdir("/")' to ensure that our process doesn't keep any director
y in
     use. Failure to do this could make it so that an administrator
     couldn't unmount a filesystem, because it was our current directo
ry.

     [Equivalently, we could change to any directory containing files

     important to the daemon's operation.]

  5. `umask(0)' so that we have complete control over the permissions 
of
     anything we write. We don't know what umask we may have inherited
.

     [This step is optional]

  6. `close()' fds 0, 1, and 2. This releases the standard in, out, an
d
     error we inherited from our parent process. We have no way of kno
wing
     where these fds might have been redirected to. Note that many dae
mons
     use `sysconf()' to determine the limit `_SC_OPEN_MAX'.  `_SC_OPEN
_MAX'
     tells you the maximun open files/process. Then in a loop, the dae
mon
     can close all possible file descriptors. You have to decide if yo
u
     need to do this or not.  If you think that there might be
     file-descriptors open you should close them, since there's a limi
t on
     number of concurrent file descriptors.

  7. Establish new open descriptors for stdin, stdout and stderr. Even
 if
     you don't plan to use them, it is still a good idea to have them 
open.
     The precise handling of these is a matter of taste; if you have a

     logfile, for example, you might wish to open it as stdout or stde
rr,
     and open `/dev/null' as stdin; alternatively, you could open
     `/dev/console' as stderr and/or stdout, and `/dev/null' as stdin,
 or
     any other combination that makes sense for your particular daemon
.

Almost none of this is necessary (or advisable) if your daemon is bein
g
started by `inetd'.  In that case, stdin, stdout and stderr are all se
t up
for you to refer to the network connection, and the `fork()'s and sess
ion
manipulation should *not* be done (to avoid confusing `inetd').  Only 
the
`chdir()' and `umask()' steps remain as useful.

1.8 How can I look at process in the system like ps does?
=========================================================

You really *don't* want to do this.

The most portable way, by far, is to do `popen(pscmd, "r")' and parse 
the
output. (pscmd should be something like `"ps -ef"' on SysV systems; on
 BSD
systems there are many possible display options: choose one.)

In the examples section, there are two complete versions of this; one 
for
SunOS 4, which requires root permission to run and uses the `kvm_*'
routines to read the information from kernel data structures; and anot
her
for SVR4 systems (including SunOS 5), which uses the `/proc' filesyste
m.

It's even easier on systems with an SVR4.2-style `/proc'; just read a

psinfo_t structure from the file `/proc/PID/psinfo' for each PID of
interest. However, this method, while probably the cleanest, is also
perhaps the least well-supported. (On FreeBSD's `/proc', you read a
semi-undocumented printable string from `/proc/PID/status'; Linux has

something similar.)

1.9 Given a pid, how can I tell if it's a running program?
==========================================================

Use `kill()' with 0 for the signal number.

There are four possible results from this call:

   * `kill()' returns 0

        - this implies that a process exists with the given PID, and t
he
          system would allow you to send signals to it. It is
          system-dependent whether the process could be a zombie.

   * `kill()' returns -1, `errno == ESRCH'

        - either no process exists with the given PID, or security
          enhancements are causing the system to deny its existence. (
On
          some systems, the process could be a zombie.)

   * `kill()' returns -1, `errno == EPERM'

        - the system would not allow you to kill the specified process
.
          This means that either the process exists (again, it could b
e a
          zombie) or draconian security enhancements are present (e.g.
 your
          process is not allowed to send signals to *anybody*).

   * `kill()' returns -1, with some other value of `errno'

        - you are in trouble!

The most-used technique is to assume that success or failure with `EPE
RM'
implies that the process exists, and any other error implies that it
doesn't.

An alternative exists, if you are writing specifically for a system (o
r all
those systems) that provide a `/proc' filesystem: checking for the
existence of `/proc/PID' may work.

1.10 What's the return value of system/pclose/waitpid?
======================================================

     The return value of `system()', `pclose()', or `waitpid()' doesn'
t
     seem to be the exit value of my process...  or the exit value is

     shifted left 8 bits... what's the deal?

The man page is right, and so are you!  If you read the man page for
`waitpid()' you'll find that the return code for the process is encode
d.
The value returned by the process is normally in the top 16 bits, and 
the
rest is used for other things.  You can't rely on this though, not if 
you
want to be portable, so the suggestion is that you use the macros prov
ided.
These are usually documented under `wait()' or `wstat'.

Macros defined for the purpose (in `<sys/wait.h>') include (stat is th
e
value returned by `waitpid()'):

`WIFEXITED(stat)'
     Non zero if child exited normally.

`WEXITSTATUS(stat)'
     exit code returned by child

`WIFSIGNALED(stat)'
     Non-zero if child was terminated by a signal

`WTERMSIG(stat)'
     signal number that terminated child

`WIFSTOPPED(stat)'
     non-zero if child is stopped

`WSTOPSIG(stat)'
     number of signal that stopped child

`WIFCONTINUED(stat)'
     non-zero if status was for continued child

`WCOREDUMP(stat)'
     If `WIFSIGNALED(stat)' is non-zero, this is non-zero if the proce
ss
     left behind a core dump.

1.11 How do I find out about a process' memory usage?
=====================================================

Look at `getrusage()', if available.

1.12 Why do processes never decrease in size?
=============================================

When you free memory back to the heap with `free()', on almost all sys
tems
that *doesn't* reduce the memory usage of your program.  The memory
`free()'d is still part of the process' address space, and will be use
d to
satisfy future `malloc()' requests.

If you really need to free memory back to the system, look at using
`mmap()' to allocate private anonymous mappings.  When these are unmap
ped,
the memory really is released back to the system.  Certain implementat
ions
of `malloc()' (e.g. in the GNU C Library) automatically use `mmap()' w
here
available to perform large allocations; these blocks are then returned
 to
the system on `free()'.

Of course, if your program increases in size when you think it shouldn
't,
you may have a `memory leak' - a bug in your program that results in u
nused
memory not being freed.

1.13 How do I change the name of my program (as seen by `ps')?
==============================================================

On BSDish systems, the `ps' program actually looks into the address sp
ace
of the running process to find the current `argv[]', and displays that
.
That enables a program to change its `name' simply by modifying `argv[
]'.

On SysVish systems, the command name and usually the first 80 bytes of
 the
parameters are stored in the process' u-area, and so can't be directly

modified. There may be a system call to change this (unlikely), but
otherwise the only way is to perform an `exec()', or write into kernel

memory (dangerous, and only possible if running as root).

Some systems (notably Solaris) may have two separate versions of `ps',
 one
in `/usr/bin/ps' with SysV behaviour, and one in `/usr/ucb/ps' with BS
D
behaviour. On these systems, if you change `argv[]', then the BSD vers
ion
of `ps' will reflect the change, and the SysV version won't.

Check to see if your system has a function `setproctitle()'.

1.14 How can I find a process' executable file?
===============================================

This would be a good candidate for a list of `Frequently Unanswered
Questions', because the fact of asking the question usually means that
 the
design of the program is flawed. :-)

You can make a `best guess' by looking at the value of `argv[0]'.  If 
this
contains a `/', then it is probably the absolute or relative (to the
current directory at program start) path of the executable.  If it doe
s
not, then you can mimic the shell's search of the `PATH' variable, loo
king
for the program.  However, success is not guaranteed, since it is poss
ible
to invoke programs with arbitrary values of `argv[0]', and in any case
 the
executable may have been renamed or deleted since it was started.

If all you want is to be able to print an appropriate invocation name 
with
error messages, then the best approach is to have `main()' save the va
lue
of `argv[0]' in a global variable for use by the entire program.  Whil
e
there is no guarantee whatsoever

--
Life it seems to fade away,
Drifting further every day...
---我本楚狂人,凤歌笑孔丘---

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.103.100.243]

[关闭][返回]