In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What this article shares with you is about how to apply the prctl () function. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
T prctl (int option,unsigned longarg2,unsigned long arg3,unsigned long arg4,unsigned long arg5)
This system call instruction is designed for the process, and the clear choice depends on the option:
PR_GET_PDEATHSIG: returns the processor signal
PR_SET_PDEATHSIG: arg2 is entered as the processor signal pdeath, which, as the name suggests, is accepted by the process if the parent process is no longer available.
PR_GET_DUMPABLE: returns the processor flag dumpable
PR_SET_DUMPABLE: arg2 is entered as the processor flag dumpable.
PR_GET_NAME: returns the process name of the calling process to the parameter arg2; (Since Linux2.6.9)
PR_SET_NAME: use the parameter arg2 as the frequent name of the calling process. (SinceLinux 2.6.11)
PR_GET_TIMING:
PR_SET_TIMING: determines and modifies process timing mode, which is used to enable traditional process timing mode
PR_TIMING_STATISTICAL, or to enable timestamp-based process timing mode
PR_TIMING_TIMESTAMP .
CAP_CHOWN function:
In a system defined by the _ POSIX_CHOWN_RESTRICTED function. This overrides all permissions to change the owner and group of system files
CAP_DAC_OVERRIED function:
If _ POSIX_ACL is defined, it crosses all DAC access, including ACL execution access, and excludes it with the CAP_LINUX_IMMUTABLE function
Access to DAC
CAP_DAC_READ_SEARCH function:
If _ POSIX_ACL is defined, all DAC read limits are exceeded
And search all files and directories, including ACL restrictions. Use CAP_LINUX_IMMUTABLE to restrict DAC access
CAP_FOWNER function:
The file says that some restrictions are allowed, such as the owner of the file, ID, must be the same as the user ID, except that CAP_FSETID is available. It will not exceed the MAC and DAC restrictions.
CAP_FSETID function:
Beyond the limit that the user's ID must match the owner ID when setting the S_ISUID and S_ISGID bits of the file, when setting the S-ISGID bit, the group ID
Restrictions that must match the owner ID, use chown to set the functional limits for S_ISUID and S_ISGID
CAP_FS_MASK function:
Used to respond to suser () or fsuser ().
CAP_KILL function:
A process with a valid user ID must match the function of a valid user ID when sending a signal
CAP_SETGID function:
Allow setgid () function, allow setgroups ()
Allow counterfeiting of gid in socket
CAP_SETUID function:
Allow set*uid () function to allow forged pid in socket
CAP_SETPCAP function:
Give all permits to all pid. Or delete all licenses.
CAP_LINUX_IMMUTABLE function:
Allow changes to S_IMMUTABLE and S_APPEND file properties
CAP_NET_BIND_SERVICE function:
Allow binding of TCP/UDP sockets under 1024
CAP_NET_BROADCAST function:
Allow broadcast, monitor multicast
CAP_NET_ADMIN function:
Allow configuration of interfac
Allow management of IP Firewall IP masquerading and accounts
Allow configuration of socket debugging options
Allow routing table modification
Allows you to configure the group properties of processes on socket
Allow transparent proxies to bind all addresses
Allow configuration of TOS (service type)
Allow configuration of promiscuous mode
Allow drive status to be cleared
Allow multicasting
Allow you to read or write system records
CAP_NET_RAW function:
Allow RAW sockets
Allow PACKET sockets
CAP_IPC_LOCK function:
Allow trivial fixing of shared memory segments
Allow mlock and mlockall
CAP_IPC_OWNER function:
Beyond the IPC ownership check
CAP_SYS_MODULE function:
Insert or remove kernel modules
CAP_SYS_RAWIO function:
Allow access to ioperm/iopl and / dev/prot
Allow / dev/mem and / dev/kmem access
Allow block devices to access (/ dev/ [sh] dongs? )
CAP_SYS_CHROOT function:
Allow chroot ()
CAP_SYS_PTRACE function:
Allow ptrace () any process
CAP_SYS_PACCT function:
Allow configuration of process accounts
CAP_SYS_ADMIN function:
Allow configuration of security keys
Allow management of random devices
Allow device management
Allows you to check and configure disk limits
Allow configuration of kernel logs
Allow configuration of domain names
Allow configuration of hostname
Allow calls to the bdflush () command
Allow mount () and umount () commands
Allow configuration of smb connections
Allow ioctls for root
Allow nfsservctl
Allow VM86_REQUEST_IRQ
Allow pci configuration to be read and written on alpha
Allow irix_prctl on mips
Allow all m68k caches to be flushed
Allow deletion of semaphores
Replace "chown" IPC message queues, flags and shared memory with CAP_CHOWN
Allow locking or unlocking shared memory segments
Allow switch swap
Allow camouflage of pids in socket
Allows you to set cache refresh for block devices
Allow setting of floppy disk drives
Allow switch DMA switch
Allow management of md devices
Allows you to manage ide drivers
Allow access to nvram Devic
Allows you to manage apm_bios, serial or bttv TV devices
Allow commands to be generated under the driver of isdn CAPI
Allow non-standard configuration of pci to be read
Allow DDI to debug ioctl
Allow qic-117 commands to be sent
Allows you to start or disable the control of SCSI and send SCSI commands that allow you to configure encrypted passwords on the loop file system
CAP_SYS_BOOT function:
The reboot () command is allowed
CAP_SYS_NICE function:
Allow you to increase or set the priority of other processes
Allow FISO and real-time scheduling and configuration in your own process
CAP_SYS_RESOURCE function:
Set resource limits beyond resource limits
Exceed the quota limit
Beyond the reserved ext2 file system
Allow real-time clock interrupts greater than 64hz
Over the maximum number of control terminals
Beyond the maximum number of keys
CAP_SYS_TIME function:
Allow processing of the system clock
Allow _ stime
Allows you to set the real-time clock
CAP_SYS_TTY_CONFIG function:
Allow configuration of end devices
Allow vhangup () terminals
Return value
PR_GET_DUMPABLE and PR_GET_KEEPCAPS return 0 or 1 if they are successful. All other option values return 0 on success.
Return-1 in case of error and set the corresponding error number.
The value of EINVAL----option is incorrect, or when it is PR_SET_PDEATHSIG, the value of the parameter arg2 is not 0 or signal number.
EBADF---- invalid descriptor
Example: for multithreaded applications, if you can name each thread, the convenience of debugging is self-evident.
# include
# include
# include
Void* tmain (void*arg)
{
Char name [32]
Prctl (PR_SET_NAME, (unsignedlong) "xx")
Prctl (PR_GET_NAME, (unsignedlong) name)
Printf ("% SSPO", name)
While (1)
Sleep (1)
}
Int main (void)
{
Pthread_t tid
Pthread_create (& tid,NULL, tmain,NULL)
Pthread_join (tid,NULL)
Return 0
}
Compile and run:
Xiaosuo@gentux test $gcc t_threadname.c-lpthread
Xiaosuo@gentux test $. / a.out
Xx
At the other terminal, find a.out 's pid through ps:
Xiaosuo@gentux test $ps aux | grep a.out
Xiaosuo 29882 0.0 0.0 14144 544 pts/6 Sl+ 16:23 0:00. / a.out
See if the naming works:
Xiaosuo@gentux test $cd / proc/29882/task/
Xiaosuo@gentux task $ls
29882 29883
Xiaosuo@gentux task $cd 29883 /
Xiaosuo@gentux 29883$ cat cmdline
. / a.outxiaosuo@gentux 29883 $
It's a little depressing that cmdline still shows. / a.out. Check the return value of prctl through the xx and strace printed at run time to confirm that prctl is indeed running successfully. I suspected that the name could only be obtained through prctl. I was a little lost, but I was still reluctant. Look at ps's man and experiment, and finally find the "xx":
Xiaosuo@gentux 29883$ ps-L-p 29882
PID LWP TTY TIME CMD
29882 29882 pts/6 00:00:00 a.out
29882 29883 pts/6 00:00:00 xx
How to rename a process under Linux:
Using the system function prctl (), declare as follows:
# include
Int prctl (int option, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5)
For specific usage, please refer to http://www.kernel.org/doc/man-pages/online/pages/man2/prctl.2.html
Process rename code:
Prctl (PR_SET_NAME, "process_name", NULL, NULL, NULL)
The first parameter is the operation type. Specify PR_SET_NAME, that is, set the process name.
The second parameter is the process name string, which is up to 16 bytes long
The above is how to apply the prctl () function. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.