/* Asynchronous subprocess control for GNU Emacs.
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995,
- 1996, 1998, 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 1996, 1998, 1999, 2001, 2002, 2003, 2004,
+ 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-
-#if defined(WINDOWSNT) || defined(UNIX98_PTYS)
-#include <stdlib.h>
#include <fcntl.h>
-#endif /* not WINDOWSNT */
#ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
#include <sys/socket.h>
/* QCfilter is defined in keyboard.c. */
extern Lisp_Object QCfilter;
+Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
+Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
+Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
+Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
+
#ifdef HAVE_SOCKETS
#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork))
#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork))
#ifdef PTY_TTY_NAME_SPRINTF
PTY_TTY_NAME_SPRINTF
#else
- sprintf (pty_name, "/dev/tty%c%x", c, i);
+ sprintf (pty_name, "/dev/tty%c%x", c, i);
#endif /* no PTY_TTY_NAME_SPRINTF */
if (access (pty_name, 6) != 0)
{
p->raw_status_new = 0;
p->status = Qrun;
p->mark = Fmake_marker ();
+ p->kill_without_query = 0;
#ifdef ADAPTIVE_READ_BUFFERING
p->adaptive_read_buffering = 0;
return XPROCESS (process)->type;
}
#endif
-
+
DEFUN ("process-type", Fprocess_type, Sprocess_type, 1, 1, 0,
doc: /* Return the connection type of PROCESS.
The value is either the symbol `real', `network', or `serial'.
insert_string (tembuf);
}
else if (NETCONN1_P (p))
- {
+ {
/* For a local socket, there is no host name,
so display service instead. */
Lisp_Object host = Fplist_get (p->childp, QChost);
(DATAGRAM_CHAN_P (p->infd) ? "datagram" : "stream"),
(STRINGP (host) ? (char *)SDATA (host) : "?"));
insert_string (tembuf);
- }
+ }
else if (SERIALCONN1_P (p))
{
Lisp_Object port = Fplist_get (p->childp, QCport);
unsigned char *cp;
register struct Lisp_Vector *p;
+ /* Workaround for a bug in getsockname on BSD: Names bound to
+ sockets in the UNIX domain are inaccessible; getsockname returns
+ a zero length name. */
+ if (len < OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family))
+ return build_string ("");
+
switch (sa->sa_family)
{
case AF_INET:
address = Fmake_vector (make_number (len), Qnil);
p = XVECTOR (address);
p->contents[--len] = make_number (ntohs (sin->sin_port));
- cp = (unsigned char *)&sin->sin_addr;
+ cp = (unsigned char *) &sin->sin_addr;
break;
}
#ifdef AF_INET6
case AF_INET6:
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
- uint16_t *ip6 = (uint16_t *)&sin6->sin6_addr;
+ uint16_t *ip6 = (uint16_t *) &sin6->sin6_addr;
len = sizeof (sin6->sin6_addr)/2 + 1;
address = Fmake_vector (make_number (len), Qnil);
p = XVECTOR (address);
}
#endif
default:
- len -= sizeof (sa->sa_family);
+ len -= OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family);
address = Fcons (make_number (sa->sa_family),
Fmake_vector (make_number (len), Qnil));
p = XVECTOR (XCDR (address));
- cp = (unsigned char *) sa + sizeof (sa->sa_family);
+ cp = (unsigned char *) &sa->sa_family + sizeof (sa->sa_family);
break;
}
#ifdef HAVE_GAI_STRERROR
error ("%s/%s %s", SDATA (host), portstring, gai_strerror(ret));
#else
- error ("%s/%s getaddrinfo error %d", SDATA (host), portstring, ret);
+ error ("%s/%s getaddrinfo error %d", SDATA (host), portstring, ret);
#endif
immediate_quit = 0;
/* Parse network options in the arg list.
We simply ignore anything which isn't a known option (including other keywords).
- An error is signaled if setting a known option fails. */
+ An error is signaled if setting a known option fails. */
for (optn = optbits = 0; optn < nargs-1; optn += 2)
optbits |= set_socket_option (s, args[optn], args[optn+1]);
Non-nil arg PROCESS means do not return until some output has been received
from PROCESS.
-Non-nil second arg SECONDS and third arg MILLISEC are number of
-seconds and milliseconds to wait; return after that much time whether
-or not there is input. If SECONDS is a floating point number,
+Non-nil second arg SECONDS and third arg MILLISEC are number of seconds
+and milliseconds to wait; return after that much time whether or not
+there is any subprocess output. If SECONDS is a floating point number,
it specifies a fractional number of seconds to wait.
The MILLISEC argument is obsolete and should be avoided.
QUIT;
#ifdef SYNC_INPUT
else
- {
- if (interrupt_input_pending)
- handle_async_input ();
- if (pending_atimers)
- do_pending_atimers ();
- }
+ {
+ if (interrupt_input_pending)
+ handle_async_input ();
+ if (pending_atimers)
+ do_pending_atimers ();
+ }
#endif
/* Exit now if the cell we're waiting for became non-nil. */
}
/* Don't wait for output from a non-running process. Just
- read whatever data has already been received. */
+ read whatever data has already been received. */
if (wait_proc && wait_proc->raw_status_new)
update_status (wait_proc);
if (wait_proc
if (nread == 0)
break;
- if (0 < nread)
- {
+ if (0 < nread)
+ {
total_nread += nread;
got_some_input = 1;
}
#ifdef EIO
else if (nread == -1 && EIO == errno)
- break;
+ break;
#endif
#ifdef EAGAIN
else if (nread == -1 && EAGAIN == errno)
- break;
+ break;
#endif
#ifdef EWOULDBLOCK
else if (nread == -1 && EWOULDBLOCK == errno)
- break;
+ break;
#endif
}
if (total_nread > 0 && do_display)
}
#endif
#ifdef HAVE_NS
- nfds = ns_select
+ nfds = ns_select
#else
- nfds = select
+ nfds = select
#endif
- (max (max (max_process_desc, max_keyboard_desc),
+ (max (max (max_process_desc, max_keyboard_desc),
max_gpm_desc) + 1,
&Available,
#ifdef NON_BLOCKING_CONNECT
#ifdef GNU_LINUX
/* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
- So only use it on systems where it is known to work. */
+ So only use it on systems where it is known to work. */
{
int xlen = sizeof(xerrno);
if (getsockopt(channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen))
if (p->pty_flag)
{
/* Starting this at zero is always correct when not the first
- iteration because the previous iteration ended by sending C-d.
+ iteration because the previous iteration ended by sending C-d.
It may not be correct for the first iteration
if a partial line was sent in a separate send_process call.
If that proves worth handling, we need to save linepos
by sending an input character to it. */
/* TERMIOS is the latest and bestest, and seems most likely to
- work. If the system has it, use it. */
+ work. If the system has it, use it. */
#ifdef HAVE_TERMIOS
struct termios t;
cc_t *sig_char = NULL;
#endif /* no WUNTRACED */
/* Keep trying to get a status until we get a definitive result. */
do
- {
+ {
errno = 0;
pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
}
if (WIFEXITED (w))
synch_process_retcode = WRETCODE (w);
else if (WIFSIGNALED (w))
- synch_process_termsig = WTERMSIG (w);
+ synch_process_termsig = WTERMSIG (w);
/* Tell wait_reading_process_output that it needs to wake up and
look around. */
to use up all the processes that have something to tell us. */
#if (defined WINDOWSNT \
|| (defined USG && !defined GNU_LINUX \
- && !(defined HPUX && defined WNOHANG)))
+ && !(defined HPUX && defined WNOHANG)))
#if defined (USG) && ! defined (POSIX_SIGNALS)
signal (signo, sigchld_handler);
#endif
return 0;
}
\f
+/* Enumeration of and access to system processes a-la ps(1). */
+
+DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes,
+ 0, 0, 0,
+ doc: /* Return a list of numerical process IDs of all running processes.
+If this functionality is unsupported, return nil.
+
+See `system-process-attributes' for getting attributes of a process
+given its ID. */)
+ ()
+{
+ return list_system_processes ();
+}
+
+DEFUN ("system-process-attributes", Fsystem_process_attributes,
+ Ssystem_process_attributes, 1, 1, 0,
+ doc: /* Return attributes of the process given by its PID, a number.
+
+Value is an alist where each element is a cons cell of the form
+
+ \(KEY . VALUE)
+
+If this functionality is unsupported, the value is nil.
+
+See `list-system-processes' for getting a list of all process IDs.
+
+The KEYs of the attributes that this function may return are listed
+below, together with the type of the associated VALUE (in parentheses).
+Not all platforms support all of these attributes; unsupported
+attributes will not appear in the returned alist.
+Unless explicitly indicated otherwise, numbers can have either
+integer or floating point values.
+
+ euid -- Effective user User ID of the process (number)
+ user -- User name corresponding to euid (string)
+ egid -- Effective user Group ID of the process (number)
+ group -- Group name corresponding to egid (string)
+ comm -- Command name (executable name only) (string)
+ state -- Process state code, such as "S", "R", or "T" (string)
+ ppid -- Parent process ID (number)
+ pgrp -- Process group ID (number)
+ sess -- Session ID, i.e. process ID of session leader (number)
+ ttname -- Controlling tty name (string)
+ tpgid -- ID of foreground process group on the process's tty (number)
+ minflt -- number of minor page faults (number)
+ majflt -- number of major page faults (number)
+ cminflt -- cumulative number of minor page faults (number)
+ cmajflt -- cumulative number of major page faults (number)
+ utime -- user time used by the process, in the (HIGH LOW USEC) format
+ stime -- system time used by the process, in the (HIGH LOW USEC) format
+ time -- sum of utime and stime, in the (HIGH LOW USEC) format
+ cutime -- user time used by the process and its children, (HIGH LOW USEC)
+ cstime -- system time used by the process and its children, (HIGH LOW USEC)
+ ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
+ pri -- priority of the process (number)
+ nice -- nice value of the process (number)
+ thcount -- process thread count (number)
+ start -- time the process started, in the (HIGH LOW USEC) format
+ vsize -- virtual memory size of the process in KB's (number)
+ rss -- resident set size of the process in KB's (number)
+ etime -- elapsed time the process is running, in (HIGH LOW USEC) format
+ pcpu -- percents of CPU time used by the process (floating-point number)
+ pmem -- percents of total physical memory used by process's resident set
+ (floating-point number)
+ args -- command line which invoked the process (string). */)
+ (pid)
+
+ Lisp_Object pid;
+{
+ return system_process_attributes (pid);
+}
+\f
void
init_process ()
{
}
#endif /* HAVE_SOCKETS */
-#if defined (DARWIN)
+#if defined (DARWIN_OS)
/* PTYs are broken on Darwin < 6, but are sometimes useful for interactive
processes. As such, we only change the default value. */
if (initialized)
staticpro (&deleted_pid_list);
#endif
+ Qeuid = intern ("euid");
+ staticpro (&Qeuid);
+ Qegid = intern ("egid");
+ staticpro (&Qegid);
+ Quser = intern ("user");
+ staticpro (&Quser);
+ Qgroup = intern ("group");
+ staticpro (&Qgroup);
+ Qcomm = intern ("comm");
+ staticpro (&Qcomm);
+ Qstate = intern ("state");
+ staticpro (&Qstate);
+ Qppid = intern ("ppid");
+ staticpro (&Qppid);
+ Qpgrp = intern ("pgrp");
+ staticpro (&Qpgrp);
+ Qsess = intern ("sess");
+ staticpro (&Qsess);
+ Qttname = intern ("ttname");
+ staticpro (&Qttname);
+ Qtpgid = intern ("tpgid");
+ staticpro (&Qtpgid);
+ Qminflt = intern ("minflt");
+ staticpro (&Qminflt);
+ Qmajflt = intern ("majflt");
+ staticpro (&Qmajflt);
+ Qcminflt = intern ("cminflt");
+ staticpro (&Qcminflt);
+ Qcmajflt = intern ("cmajflt");
+ staticpro (&Qcmajflt);
+ Qutime = intern ("utime");
+ staticpro (&Qutime);
+ Qstime = intern ("stime");
+ staticpro (&Qstime);
+ Qtime = intern ("time");
+ staticpro (&Qtime);
+ Qcutime = intern ("cutime");
+ staticpro (&Qcutime);
+ Qcstime = intern ("cstime");
+ staticpro (&Qcstime);
+ Qctime = intern ("ctime");
+ staticpro (&Qctime);
+ Qpri = intern ("pri");
+ staticpro (&Qpri);
+ Qnice = intern ("nice");
+ staticpro (&Qnice);
+ Qthcount = intern ("thcount");
+ staticpro (&Qthcount);
+ Qstart = intern ("start");
+ staticpro (&Qstart);
+ Qvsize = intern ("vsize");
+ staticpro (&Qvsize);
+ Qrss = intern ("rss");
+ staticpro (&Qrss);
+ Qetime = intern ("etime");
+ staticpro (&Qetime);
+ Qpcpu = intern ("pcpu");
+ staticpro (&Qpcpu);
+ Qpmem = intern ("pmem");
+ staticpro (&Qpmem);
+ Qargs = intern ("args");
+ staticpro (&Qargs);
+
DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes,
doc: /* *Non-nil means delete processes immediately when they exit.
A value of nil means don't delete them until `list-processes' is run. */);
defsubr (&Sprocess_coding_system);
defsubr (&Sset_process_filter_multibyte);
defsubr (&Sprocess_filter_multibyte_p);
+ defsubr (&Slist_system_processes);
+ defsubr (&Ssystem_process_attributes);
}
\f
#include <sys/types.h>
#include <errno.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#include "lisp.h"
#include "systime.h"
extern EMACS_TIME timer_check ();
extern int timers_run;
-Lisp_Object QCtype;
+Lisp_Object QCtype, QCname;
+
+Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
+Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
+Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
+Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
/* As described above, except assuming that there are no subprocesses:
{
}
+DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes,
+ 0, 0, 0,
+ doc: /* Return a list of numerical process IDs of all running processes.
+If this functionality is unsupported, return nil.
+
+See `system-process-attributes' for getting attributes of a process
+given its ID. */)
+ ()
+{
+ return list_system_processes ();
+}
+
+DEFUN ("system-process-attributes", Fsystem_process_attributes,
+ Ssystem_process_attributes, 1, 1, 0,
+ doc: /* Return attributes of the process given by its PID, a number.
+
+Value is an alist where each element is a cons cell of the form
+
+ \(KEY . VALUE)
+
+If this functionality is unsupported, the value is nil.
+
+See `list-system-processes' for getting a list of all process IDs.
+
+The KEYs of the attributes that this function may return are listed
+below, together with the type of the associated VALUE (in parentheses).
+Not all platforms support all of these attributes; unsupported
+attributes will not appear in the returned alist.
+Unless explicitly indicated otherwise, numbers can have either
+integer or floating point values.
+
+ euid -- Effective user User ID of the process (number)
+ user -- User name corresponding to euid (string)
+ egid -- Effective user Group ID of the process (number)
+ group -- Group name corresponding to egid (string)
+ comm -- Command name (executable name only) (string)
+ state -- Process state code, such as "S", "R", or "T" (string)
+ ppid -- Parent process ID (number)
+ pgrp -- Process group ID (number)
+ sess -- Session ID, i.e. process ID of session leader (number)
+ ttname -- Controlling tty name (string)
+ tpgid -- ID of foreground process group on the process's tty (number)
+ minflt -- number of minor page faults (number)
+ majflt -- number of major page faults (number)
+ cminflt -- cumulative number of minor page faults (number)
+ cmajflt -- cumulative number of major page faults (number)
+ utime -- user time used by the process, in the (HIGH LOW USEC) format
+ stime -- system time used by the process, in the (HIGH LOW USEC) format
+ time -- sum of utime and stime, in the (HIGH LOW USEC) format
+ cutime -- user time used by the process and its children, (HIGH LOW USEC)
+ cstime -- system time used by the process and its children, (HIGH LOW USEC)
+ ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
+ pri -- priority of the process (number)
+ nice -- nice value of the process (number)
+ thcount -- process thread count (number)
+ start -- time the process started, in the (HIGH LOW USEC) format
+ vsize -- virtual memory size of the process in KB's (number)
+ rss -- resident set size of the process in KB's (number)
+ etime -- elapsed time the process is running, in (HIGH LOW USEC) format
+ pcpu -- percents of CPU time used by the process (floating-point number)
+ pmem -- percents of total physical memory used by process's resident set
+ (floating-point number)
+ args -- command line which invoked the process (string). */)
+ (pid)
+
+ Lisp_Object pid;
+{
+ return system_process_attributes (pid);
+}
+
void
init_process ()
{
{
QCtype = intern (":type");
staticpro (&QCtype);
+ QCname = intern (":name");
+ staticpro (&QCname);
+ QCtype = intern (":type");
+ staticpro (&QCtype);
+ QCname = intern (":name");
+ staticpro (&QCname);
+ Qeuid = intern ("euid");
+ staticpro (&Qeuid);
+ Qegid = intern ("egid");
+ staticpro (&Qegid);
+ Quser = intern ("user");
+ staticpro (&Quser);
+ Qgroup = intern ("group");
+ staticpro (&Qgroup);
+ Qcomm = intern ("comm");
+ staticpro (&Qcomm);
+ Qstate = intern ("state");
+ staticpro (&Qstate);
+ Qppid = intern ("ppid");
+ staticpro (&Qppid);
+ Qpgrp = intern ("pgrp");
+ staticpro (&Qpgrp);
+ Qsess = intern ("sess");
+ staticpro (&Qsess);
+ Qttname = intern ("ttname");
+ staticpro (&Qttname);
+ Qtpgid = intern ("tpgid");
+ staticpro (&Qtpgid);
+ Qminflt = intern ("minflt");
+ staticpro (&Qminflt);
+ Qmajflt = intern ("majflt");
+ staticpro (&Qmajflt);
+ Qcminflt = intern ("cminflt");
+ staticpro (&Qcminflt);
+ Qcmajflt = intern ("cmajflt");
+ staticpro (&Qcmajflt);
+ Qutime = intern ("utime");
+ staticpro (&Qutime);
+ Qstime = intern ("stime");
+ staticpro (&Qstime);
+ Qtime = intern ("time");
+ staticpro (&Qtime);
+ Qcutime = intern ("cutime");
+ staticpro (&Qcutime);
+ Qcstime = intern ("cstime");
+ staticpro (&Qcstime);
+ Qctime = intern ("ctime");
+ staticpro (&Qctime);
+ Qpri = intern ("pri");
+ staticpro (&Qpri);
+ Qnice = intern ("nice");
+ staticpro (&Qnice);
+ Qthcount = intern ("thcount");
+ staticpro (&Qthcount);
+ Qstart = intern ("start");
+ staticpro (&Qstart);
+ Qvsize = intern ("vsize");
+ staticpro (&Qvsize);
+ Qrss = intern ("rss");
+ staticpro (&Qrss);
+ Qetime = intern ("etime");
+ staticpro (&Qetime);
+ Qpcpu = intern ("pcpu");
+ staticpro (&Qpcpu);
+ Qpmem = intern ("pmem");
+ staticpro (&Qpmem);
+ Qargs = intern ("args");
+ staticpro (&Qargs);
defsubr (&Sget_buffer_process);
defsubr (&Sprocess_inherit_coding_system_flag);
+ defsubr (&Slist_system_processes);
+ defsubr (&Ssystem_process_attributes);
}
\f