#include <unistd.h>
pid_t getsid(pid_t pid);
cat /etc/passwd |grep "beyes" |wc -c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
pid_t mypid = getpid();
printf ("%d\n", getsid(mypid));
return 0;
}
./getsid
4796
$ echo $$
4796
$ps aux |grep 4796
beyes 4796 0.0 0.1 5276 2532 pts/2 Ss 08:48 0:00 -bash
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i = atoi(argv[1]);
printf ("%d\n", getsid(i));
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int i = 0;
int main()
{
while (1) {
if (i == 100) {
return 0;
}
printf ("hello world\n");
sleep (5);
i++;
}
}
$ ps aux |grep tmp
root 10 0.0 0.0 0 0 ? S 17:39 0:00 [kdevtmpfs]
beyes 1254 0.0 1.6 50312 34040 ? SNl 17:40 0:01 /usr/bin/virtuoso-t +foreground +configfile /tmp/virtuoso_hX1248.ini +wait
beyes 2155 0.0 0.0 2012 272 pts/2 S+ 18:08 0:00 ./tmp
beyes 2242 0.0 0.0 6448 800 pts/3 S+ 18:08 0:00 grep --color=auto tmp
$ ./getsid 2155
1974
$ echo $$
1974
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |