1 # Unix SMB/CIFS implementation.
2 # List processes (to aid debugging on systems without setproctitle)
3 # Copyright (C) 2010-2011 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Testbed for loadparm.c/params.c
20 # This module simply loads a specified configuration file and
21 # if successful, dumps it's contents to stdout. Note that the
22 # operation is performed with DEBUGLEVEL at 3.
24 # Useful for a quick 'syntax check' of a configuration file.
31 import samba
.getopt
as options
32 from samba
.netcmd
import Command
, CommandError
, Option
33 from samba
.messaging
import Messaging
35 class cmd_processes(Command
):
36 """List processes (to aid debugging on systems without setproctitle)."""
38 synopsis
= "%prog [options]"
40 takes_optiongroups
= {
41 "sambaopts": options
.SambaOptions
,
42 "versionopts": options
.VersionOptions
46 Option("--name", type=str,
47 help="Return only processes associated with one particular name"),
48 Option("--pid", type=int,
49 help="Return only names assoicated with one particular PID"),
54 def run(self
, sambaopts
, versionopts
, section_name
=None,
57 lp
= sambaopts
.get_loadparm()
58 logger
= self
.get_logger("processes")
64 ids
= msg_ctx
.irpc_servers_byname(name
)
69 self
.outf
.write("%d\n" % server_id
.pid
)
71 names
= msg_ctx
.irpc_all_servers()
73 for server_id
in name
.ids
:
74 if server_id
.pid
== int(pid
):
75 self
.outf
.write("%s\n" % name
.name
)
77 names
= msg_ctx
.irpc_all_servers()
78 self
.outf
.write(" Service: PID \n")
79 self
.outf
.write("-----------------------------\n")
81 for server_id
in name
.ids
:
82 self
.outf
.write("%-16s %6d\n" % (name
.name
, server_id
.pid
))